@OneToOne and @PrimaryKeyJoinColumn do not fetch the object on H2/HSQL database

View: New views
2 Messages — Rating Filter:   Alert me  

@OneToOne and @PrimaryKeyJoinColumn do not fetch the object on H2/HSQL database

by philk :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

I have this construct:

@Entity
class PickOrder {
   @OneToOne(optional = false, fetch = FetchType.EAGER)
   @PrimaryKeyJoinColumn(name = "auf_nr")
   OrderProgress progress;
}

@Entity
@Table(name = "order_infos")
public class OrderProgress implements Comparable<OrderProgress> {
        @Id
        @Column(name = "auf_nr", length = 18)
        String id;

        float done_percent;
        float shortfalls_percent;
        int shortfalls;

        public OrderProgress() {
        }

        @Override
        public String toString() {
                String value = this.done_percent + "%"; //$NON-NLS-1$
                if (this.shortfalls_percent > 0.f) {
                        value += " [" + this.shortfalls_percent + "%]"; //$NON-NLS-1$
//$NON-NLS-2$
                }
                return value;
        }

        public int compareTo(final OrderProgress o) {
                float result = this.done_percent - o.done_percent;
                if (result == 0.f) {
                        result = this.shortfalls_percent - o.shortfalls_percent;
                }
                return (int) result;
        }
}

When calling "select o from PickOrder" the progress object is never
filled with the data from the table (which is a view actually).
When I call "select o from PickOrder where o.id=1" it is sometimes
fetched sometimes not. The generated SQL is correct. Any Ideas what
might cause such a behaviour on H2 (HSQL)? The generated SQL does not
contain JOINs but its rather 2 calls to the DB first getting the
PickOrder list and then for each order a select to the order_infos table
is made.

Thanks,
Phil

_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

Re: @OneToOne and @PrimaryKeyJoinColumn do not fetch the object on H2/HSQL database

by James Sutherland :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Seems very odd, if the SQL is correct, then seems to be a database issue.  You may try executing the same SQL directly through JDBC.  Are you sure the data is actually there?

May be a binding issue, you can turn parameter binding off using the persistence property,

See,
http://www.eclipse.org/eclipselink/api/1.1.1/org/eclipse/persistence/config/PersistenceUnitProperties.html#JDBC_BIND_PARAMETERS

philk wrote:
Hello,

I have this construct:

@Entity
class PickOrder {
   @OneToOne(optional = false, fetch = FetchType.EAGER)
   @PrimaryKeyJoinColumn(name = "auf_nr")
   OrderProgress progress;
}

@Entity
@Table(name = "order_infos")
public class OrderProgress implements Comparable<OrderProgress> {
        @Id
        @Column(name = "auf_nr", length = 18)
        String id;

        float done_percent;
        float shortfalls_percent;
        int shortfalls;

        public OrderProgress() {
        }

        @Override
        public String toString() {
                String value = this.done_percent + "%"; //$NON-NLS-1$
                if (this.shortfalls_percent > 0.f) {
                        value += " [" + this.shortfalls_percent + "%]"; //$NON-NLS-1$
//$NON-NLS-2$
                }
                return value;
        }

        public int compareTo(final OrderProgress o) {
                float result = this.done_percent - o.done_percent;
                if (result == 0.f) {
                        result = this.shortfalls_percent - o.shortfalls_percent;
                }
                return (int) result;
        }
}

When calling "select o from PickOrder" the progress object is never
filled with the data from the table (which is a view actually).
When I call "select o from PickOrder where o.id=1" it is sometimes
fetched sometimes not. The generated SQL is correct. Any Ideas what
might cause such a behaviour on H2 (HSQL)? The generated SQL does not
contain JOINs but its rather 2 calls to the DB first getting the
PickOrder list and then for each order a select to the order_infos table
is made.

Thanks,
Phil

_______________________________________________
eclipselink-users mailing list
eclipselink-users@eclipse.org
https://dev.eclipse.org/mailman/listinfo/eclipselink-users