563 words

Join query problem with new statetment

#1
2011-07-04 19:40

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?

 

 

 

lwalkowski
lwalkowski's picture
Joined on 2010-08-25
User Post #36
#2
2011-07-07 23:02

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
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #406
#3
2011-07-08 14:29

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?

lwalkowski
lwalkowski's picture
Joined on 2010-08-25
User Post #37
#4
2011-07-08 14:45

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

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #412
#5
2011-07-08 15:51

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

lwalkowski
lwalkowski's picture
Joined on 2010-08-25
User Post #38
#6
2011-07-10 01:22

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

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)
support
support's picture
Joined on 2010-05-03
User Post #413
#7
2011-07-10 12:58

New version works fine. Thanks for a fix.

lwalkowski
lwalkowski's picture
Joined on 2010-08-25
User Post #39

Post Reply

Please read carefully the posting instructions - before posting to the ObjectDB website.

  • You may have to disable pop up blocking in order to use the toolbar (e.g. in Chrome).
  • Use ctrl + right click to open the browser context menu in the editing area (e.g. for using a browser spell checker).
  • To insert formatted lines (e.g. Java code, stack trace) - select a style in the toolbar and then insert the text in the new created block.
  • Avoid overflow of published source code examples by breaking long lines.
  • You may mark in paragraph code words (e.g. class names) with the code style (can be applied by ctrl + D).
  • Long stack traces (> 50 lines) and complex source examples (> 100 lines) should be posted as attachments.
Attachments:
Maximum file size: 32 MB
Cancel