Join query problem with new statetment

#1

Hi,

I'm trying to implement some reporting logic in my application and got nasty exception when using query with join.

The query code is:

TypedQuery<InspirationsPerSupplierResult> inspirationQuery = em.createQuery(
    "select new InspirationsPerSupplierResult(insp.id, insp.name, p.id, p.name) from Inspiration insp join insp.products p where (p.supplier = ?1)",
    InspirationsPerSupplierResult.class);
inspirationQuery.setParameter(1, sup);

Nothing special here. InspirationsPerSupplierResult is defined like this:

public class InspirationsPerSupplierResult implements Serializable {
    private static final long serialVersionUID = 1L;

    private long inspID;
    private String inspName;
    private long productID;
    private String productName;

    public InspirationsPerSupplierResult(
            long inspId, String inspName, long productId, String productName) {
        super();
        this.inspID = inspId;
        this.inspName = inspName;
        this.productID = productId;
        this.productName = productName;
    }

getters and setters below constructor. Inspiration entity (it's quite big, so let me skip some fields:

@Entity
public class Inspiration extends BaseEntity implements Serializable, Convertable {
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Id
    private long id;
    @Index
    private String name;
    (...)
    @ManyToMany(targetEntity = Product.class, fetch = FetchType.LAZY)
    private List<Product> products;

Product entity (the same as inspiration, it's quite big, so only important parts):

@Entity
public class Product extends BaseEntity implements Serializable, Convertable {
    @GeneratedValue(strategy = GenerationType.AUTO)

    @Id
    private long id;

    @Column(nullable = false)
    @Index
    private String name = "";
}

After executing above statement, there is exception:

2011-07-05 06:40:34.781 ["http-bio-8080"-exec-3] DEBUG p.h.dao.impl.InspirationDAOImpl - getPerSupplier. supplier id: 52
2011-07-05 06:40:34.847 ["http-bio-8080"-exec-3] DEBUG o.s.orm.jpa.JpaTransactionManager - Should roll back transaction but cannot - no transaction available
2011-07-05 06:40:34.847 ["http-bio-8080"-exec-3] DEBUG o.s.orm.jpa.JpaTransactionManager - Should roll back transaction but cannot - no transaction available
2011-07-05 06:40:34.872 ["http-bio-8080"-exec-3] ERROR Click - handleException:
com.objectdb.o.InternalException: null
at com.objectdb.o.InternalException.f(InternalException.java:236) ~[objectdb.jar:na]
at com.objectdb.o.REG.P(REG.java:728) ~[objectdb.jar:na]
at com.objectdb.o.REG.M(REG.java:608) ~[objectdb.jar:na]
at com.objectdb.o.REG.N(REG.java:629) ~[objectdb.jar:na]
at com.objectdb.o.REG.K(REG.java:567) ~[objectdb.jar:na]
at com.objectdb.o.REG.f(REG.java:532) ~[objectdb.jar:na]
at com.objectdb.o.VOB.j(VOB.java:188) ~[objectdb.jar:na]
at com.objectdb.o.TAI.N(TAI.java:271) ~[objectdb.jar:na]
at com.objectdb.o.TAI.j(TAI.java:234) ~[objectdb.jar:na]
at com.objectdb.o.RTT.F(RTT.java:263) ~[objectdb.jar:na]
at com.objectdb.o.RTT.E(RTT.java:235) ~[objectdb.jar:na]
at com.objectdb.o.RST.B(RST.java:169) ~[objectdb.jar:na]
at com.objectdb.o.RTT.l(RTT.java:134) ~[objectdb.jar:na]
at com.objectdb.o.RST.l(RST.java:24) ~[objectdb.jar:na]
at com.objectdb.o.RTT.C(RTT.java:179) ~[objectdb.jar:na]
at com.objectdb.o.RST.r(RST.java:110) ~[objectdb.jar:na]
at com.objectdb.o.PGT.q(PGT.java:109) ~[objectdb.jar:na]
at com.objectdb.o.RST.A(RST.java:93) ~[objectdb.jar:na]
at com.objectdb.o.RTT.l(RTT.java:132) ~[objectdb.jar:na]
at com.objectdb.o.RST.l(RST.java:24) ~[objectdb.jar:na]
at com.objectdb.o.RTT.C(RTT.java:179) ~[objectdb.jar:na]
at com.objectdb.o.RST.r(RST.java:110) ~[objectdb.jar:na]
at com.objectdb.o.PGT.q(PGT.java:109) ~[objectdb.jar:na]
at com.objectdb.o.RST.A(RST.java:93) ~[objectdb.jar:na]
at com.objectdb.o.RTT.l(RTT.java:132) ~[objectdb.jar:na]
at com.objectdb.o.RST.l(RST.java:24) ~[objectdb.jar:na]
at com.objectdb.o.TSK.i(TSK.java:146) ~[objectdb.jar:na]
at com.objectdb.o.TSK.f(TSK.java:95) ~[objectdb.jar:na]
at com.objectdb.o.MST.UQ(MST.java:531) ~[objectdb.jar:na]
at com.objectdb.o.PLN.UQ(PLN.java:481) ~[objectdb.jar:na]
at com.objectdb.o.TAI.M(TAI.java:200) ~[objectdb.jar:na]
at com.objectdb.o.TAI.Ut(TAI.java:134) ~[objectdb.jar:na]
at com.objectdb.o.MQI.Ut(MQI.java:96) ~[objectdb.jar:na]
at com.objectdb.o.PRG.ab(PRG.java:601) ~[objectdb.jar:na]
at com.objectdb.o.QRM.US(QRM.java:259) ~[objectdb.jar:na]
at com.objectdb.o.MST.US(MST.java:884) ~[objectdb.jar:na]
at com.objectdb.o.WRA.US(WRA.java:286) ~[objectdb.jar:na]
at com.objectdb.o.WSM.US(WSM.java:113) ~[objectdb.jar:na]
at com.objectdb.o.STC.r(STC.java:421) ~[objectdb.jar:na]
at com.objectdb.o.SHN.ah(SHN.java:468) ~[objectdb.jar:na]
at com.objectdb.o.SHN.J(SHN.java:146) ~[objectdb.jar:na]
at com.objectdb.o.HND.run(HND.java:133) ~[objectdb.jar:na]
at java.lang.Thread.run(Thread.java:636) ~[na:1.6.0_26]

Am I missing something here? Or is it some kind of bug?

 

 

 

#2

According to the stack trace the exception might not be related to using NEW.

There is an unexpected state during query execution. This might be caused by a schema change that is not fully supported. For example - changing an embeddable class to entity class, which results in having a class with mixed objects in the database - the old embeddable objects and the new entity objects.

For more precise diagnosis - please post a sample case that reproduces the exception (you may attach the database and the code to a support ticket if you cannot post it publicly).

ObjectDB Support
#3

Both entities Inspiration and Product were from the beginning tagged as @Entity and I don't think it was ever changed. I've changed this query to:

TypedQuery<InspirationsPerSupplierResult> inspirationQuery = em.createQuery(
          "select new InspirationsPerSupplierResult(insp, p) from Inspiration insp join insp.products p where (p.supplier = ?1)",
          InspirationsPerSupplierResult.class);

so both entities Inspiration and Product are returned and everything works fine, but is quite slow - that is expected, because of some high number of objects to download.

I forget to mention in earlier post, that changing query to:

select new InspirationsPerSupplierResult(insp.name, p.name)

"fixes" this problem. Only id from both entities cause this exception.

Can I somehow check the type of objects - embedded/entity?

#4

The embedded / entity is merely a guess. A test case will be needed to figure out the exact reason.

ObjectDB Support
#5

Please check ftp for test case and database file - UTC-5.

#6

Thank you for the test. Please try build 2.2.8_01.

ObjectDB Support
#7

New version works fine. Thanks for a fix.

Reply