-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Query fails for ManyToOne associated Entity
PostPosted: Tue Oct 07, 2008 7:14 am 
Newbie

Joined: Fri Sep 28, 2007 3:39 am
Posts: 3
Hibernate version: 3.2.5

Mapping documents: JPA Annotations

Code between sessionFactory.openSession() and session.close():
It's JPQL based unit test (used hibernate as JPA implementation).
This query was executed fine:

Query q = getEntityManager().createQuery(
"SELECT this_.aaId, " +
"this_.patient.lastNamePersistent " +
// ", " +
// "this_.patient.firstNamePersistent " +
"FROM RVOrder this_ " +
"WHERE " +
"this_.aaId IN " +
"( SELECT _1.order.aaId FROM Specimen _1 WHERE _1.aaId IN " +
"( SELECT _2.specimen.aaId FROM SpecimenBarcode _2 WHERE _2.barcode='a')))"
);
List list = q.getResultList();

but this fails during execution:

Query q = getEntityManager().createQuery(
"SELECT this_.aaId, " +
"this_.patient.lastNamePersistent " +
", " +
"this_.patient.firstNamePersistent " +
"FROM RVOrder this_ " +
"WHERE " +
"this_.aaId IN " +
"( SELECT _1.order.aaId FROM Specimen _1 WHERE _1.aaId IN " +
"( SELECT _2.specimen.aaId FROM SpecimenBarcode _2 WHERE _2.barcode='a')))"
);
List list = q.getResultList();



Full stack trace of any exception that occurs:

13:49:51,919 ERROR ResourceLocalTransactionManager:46 - Error during Transaction execution. Transaction rolled back.
java.lang.NullPointerException
at org.hibernate.hql.ast.tree.FromClause.findIntendedAliasedFromElementBasedOnCrazyJPARequirements(FromClause.java:120)
at org.hibernate.hql.ast.tree.FromClause.getFromElement(FromClause.java:107)
at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:81)
at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:255)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.collectionFunctionOrSubselect(HqlSqlBaseWalker.java:4253)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.inRhs(HqlSqlBaseWalker.java:4161)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3842)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1762)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:776)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:577)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:93)
at com.softcoputer.receive_verify.persistence.lookup.LookupEnvDepTest$2.execute(LookupEnvDepTest.java:106)
at com.softcomputer.softlab.platform.jpa.ResourceLocalTransactionManager$1.execute(ResourceLocalTransactionManager.java:72)
at com.softcomputer.softlab.platform.jpa.ResourceLocalTransactionManager$1.execute(ResourceLocalTransactionManager.java:70)
at com.softcomputer.softlab.platform.jpa.ResourceLocalTransactionManager.doInTransaction(ResourceLocalTransactionManager.java:41)
at com.softcomputer.softlab.platform.jpa.ResourceLocalTransactionManager.doInTransaction(ResourceLocalTransactionManager.java:68)
at com.softcoputer.receive_verify.persistence.lookup.LookupEnvDepTest.simpleTest2(LookupEnvDepTest.java:102)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


Name and version of the database you are using:
Oracle

The generated SQL (show_sql=true):
13:49:51,809 DEBUG QueryTranslatorImpl:246 - parse() - HQL: SELECT this_.aaId, this_.patient.lastNamePersistent , this_.patient.firstNamePersistent FROM com.softcomputer.receive_verify.business.setup.RVOrder this_ WHERE this_.aaId IN ( SELECT _1.order.aaId FROM com.softcomputer.receive_verify.business.setup.Specimen _1 WHERE _1.aaId IN ( SELECT _2.specimen.aaId FROM com.softcomputer.receive_verify.business.setup.SpecimenBarcode _2 WHERE _2.barcode='a')))
13:49:51,809 DEBUG HqlParser:320 - handleDotIdent() : new LT(2) token - [".",<15> previously: <15>,line=1,col=186,possibleID=false]
13:49:51,840 DEBUG AST:266 - --- HQL AST ---
\-[QUERY] 'query'
+-[SELECT_FROM] 'SELECT_FROM'
| +-[FROM] 'FROM'
| | \-[RANGE] 'RANGE'
| | +-[DOT] '.'
| | | +-[DOT] '.'
| | | | +-[DOT] '.'
| | | | | +-[DOT] '.'
| | | | | | +-[DOT] '.'
| | | | | | | +-[IDENT] 'com'
| | | | | | | \-[IDENT] 'softcomputer'
| | | | | | \-[IDENT] 'receive_verify'
| | | | | \-[IDENT] 'business'
| | | | \-[IDENT] 'setup'
| | | \-[IDENT] 'RVOrder'
| | \-[ALIAS] 'this_'
| \-[SELECT] 'SELECT'
| +-[DOT] '.'
| | +-[IDENT] 'this_'
| | \-[IDENT] 'aaId'
| +-[DOT] '.'
| | +-[DOT] '.'
| | | +-[IDENT] 'this_'
| | | \-[IDENT] 'patient'
| | \-[IDENT] 'lastNamePersistent'
| \-[DOT] '.'
| +-[DOT] '.'
| | +-[IDENT] 'this_'
| | \-[IDENT] 'patient'
| \-[IDENT] 'firstNamePersistent'
\-[WHERE] 'WHERE'
\-[IN] 'in'
+-[DOT] '.'
| +-[IDENT] 'this_'
| \-[IDENT] 'aaId'
\-[IN_LIST] 'inList'
\-[QUERY] 'query'
+-[SELECT_FROM] 'SELECT_FROM'
| +-[FROM] 'FROM'
| | \-[RANGE] 'RANGE'
| | +-[DOT] '.'
| | | +-[DOT] '.'
| | | | +-[DOT] '.'
| | | | | +-[DOT] '.'
| | | | | | +-[DOT] '.'
| | | | | | | +-[IDENT] 'com'
| | | | | | | \-[IDENT] 'softcomputer'
| | | | | | \-[IDENT] 'receive_verify'
| | | | | \-[IDENT] 'business'
| | | | \-[IDENT] 'setup'
| | | \-[IDENT] 'Specimen'
| | \-[ALIAS] '_1'
| \-[SELECT] 'SELECT'
| \-[DOT] '.'
| +-[DOT] '.'
| | +-[IDENT] '_1'
| | \-[IDENT] 'order'
| \-[IDENT] 'aaId'
\-[WHERE] 'WHERE'
\-[IN] 'in'
+-[DOT] '.'
| +-[IDENT] '_1'
| \-[IDENT] 'aaId'
\-[IN_LIST] 'inList'
\-[QUERY] 'query'
+-[SELECT_FROM] 'SELECT_FROM'
| +-[FROM] 'FROM'
| | \-[RANGE] 'RANGE'
| | +-[DOT] '.'
| | | +-[DOT] '.'
| | | | +-[DOT] '.'
| | | | | +-[DOT] '.'
| | | | | | +-[DOT] '.'
| | | | | | | +-[IDENT] 'com'
| | | | | | | \-[IDENT] 'softcomputer'
| | | | | | \-[IDENT] 'receive_verify'
| | | | | \-[IDENT] 'business'
| | | | \-[IDENT] 'setup'
| | | \-[IDENT] 'SpecimenBarcode'
| | \-[ALIAS] '_2'
| \-[SELECT] 'SELECT'
| \-[DOT] '.'
| +-[DOT] '.'
| | +-[IDENT] '_2'
| | \-[IDENT] 'specimen'
| \-[IDENT] 'aaId'
\-[WHERE] 'WHERE'
\-[EQ] '='
+-[DOT] '.'
| +-[IDENT] '_2'
| \-[IDENT] 'barcode'
\-[QUOTED_STRING] ''a''

13:49:51,840 DEBUG ErrorCounter:68 - throwQueryException() : no errors
13:49:51,872 DEBUG HqlSqlBaseWalker:111 - select << begin [level=1, statement=select]
13:49:51,887 DEBUG FromElement:108 - FromClause{level=1} : com.softcomputer.receive_verify.business.setup.RVOrder (this_) -> rvorder0_
13:49:51,887 DEBUG FromReferenceNode:51 - Resolved : this_ -> rvorder0_.AA_ID
13:49:51,903 DEBUG DotNode:568 - getDataType() : aaId -> org.hibernate.type.IntegerType@602b6b
13:49:51,903 DEBUG FromReferenceNode:51 - Resolved : this_.aaId -> rvorder0_.AA_ID
13:49:51,903 DEBUG FromReferenceNode:51 - Resolved : this_ -> rvorder0_.AA_ID
13:49:51,903 DEBUG DotNode:568 - getDataType() : patient -> org.hibernate.type.ManyToOneType(com.softcomputer.softlab.business.setup.Patient)
13:49:51,903 DEBUG DotNode:366 - dereferenceEntityJoin() : generating join for patient in com.softcomputer.receive_verify.business.setup.RVOrder {no alias} parent = [ ( . ( . rvorder0_.AA_ID patient ) lastNamePersistent ) ]
13:49:51,903 DEBUG FromElement:108 - FromClause{level=1} : com.softcomputer.softlab.business.setup.Patient (no alias) -> patient1_
13:49:51,903 DEBUG FromClause:233 - addJoinByPathMap() : this_.patient -> LAB_PATIENT patient1_
13:49:51,903 DEBUG FromReferenceNode:51 - Resolved : this_.patient -> rvorder0_.PATIENT
13:49:51,903 DEBUG DotNode:568 - getDataType() : lastNamePersistent -> org.hibernate.type.StringType@1a4c5b4
13:49:51,903 DEBUG FromReferenceNode:51 - Resolved : this_.patient.lastNamePersistent -> patient1_.PLNAME
13:49:51,903 DEBUG FromReferenceNode:51 - Resolved : this_ -> rvorder0_.AA_ID
13:49:51,903 DEBUG DotNode:568 - getDataType() : patient -> org.hibernate.type.ManyToOneType(com.softcomputer.softlab.business.setup.Patient)
13:49:51,903 DEBUG DotNode:366 - dereferenceEntityJoin() : generating join for patient in com.softcomputer.receive_verify.business.setup.RVOrder {no alias} parent = [ ( . ( . rvorder0_.AA_ID patient ) firstNamePersistent ) ]
13:49:51,903 DEBUG FromReferenceNode:51 - Resolved : this_.patient -> rvorder0_.PATIENT
13:49:51,903 DEBUG DotNode:568 - getDataType() : firstNamePersistent -> org.hibernate.type.StringType@1a4c5b4
13:49:51,903 DEBUG FromReferenceNode:51 - Resolved : this_.patient.firstNamePersistent -> patient1_.PFNAME
13:49:51,919 DEBUG FromReferenceNode:51 - Resolved : this_ -> rvorder0_.AA_ID
13:49:51,919 DEBUG DotNode:568 - getDataType() : aaId -> org.hibernate.type.IntegerType@602b6b
13:49:51,919 DEBUG FromReferenceNode:51 - Resolved : this_.aaId -> rvorder0_.AA_ID
13:49:51,919 DEBUG HqlSqlBaseWalker:111 - select << begin [level=2, statement=select]
13:49:51,919 ERROR ResourceLocalTransactionManager:46 - Error during Transaction execution. Transaction rolled back.

My notes:
Hello!
I need to know is described problem a known bug ? And are there workarounds here, if such exists?

If mappings are needed, I'll attach them. They are quite huge.
Key parts of mapping:

@Entity @Table
class RVOrder {
...
...
...

@OneToMany(mappedBy = "order", cascade = CascadeType.ALL)
public Set<Specimen> getSpecimens()
{
return specimens;
}

}

@Entity @Table
class Specimen {
...
...
...
@ManyToOne
@JoinColumn(name = "RVORDER")
public RVOrder getOrder()
{
return order;
}

@OneToMany(mappedBy = "specimen", cascade = CascadeType.ALL)
public Set<SpecimenBarcode> getBarcodes()
{
return barcodes;
}

}

@Entity @Table
class SpecimenBarcode{
...
...
...
@ManyToOne()
@JoinColumn(name = "SPECIMENREF")
public Specimen getSpecimen()
{
return specimen;
}

}


Top
 Profile  
 
 Post subject: More details about problem
PostPosted: Tue Oct 07, 2008 10:07 am 
Newbie

Joined: Fri Sep 28, 2007 3:39 am
Posts: 3
I've decreased an amount of selected data:

Works fine:

Query q = getEntityManager().createQuery(
"SELECT this_.aaId, " +
"this_.patient.lastNamePersistent " +
", " +
"this_.patient.firstNamePersistent " +
"FROM RVOrder this_ "
);
List list = q.getResultList();

But when add next WHERE clause (which contains subselect from Specimen table). The same NullPointerException appears:

Query q = getEntityManager().createQuery(
"SELECT this_.aaId, " +
"this_.patient.lastNamePersistent " +
", " +
"this_.patient.firstNamePersistent " +
"FROM RVOrder this_ "
+ "WHERE " +
"this_.aaId IN " +
"( SELECT spec1.order.aaId FROM Specimen spec1 WHERE spec1.specimenSource='a')"
);
List list = q.getResultList();


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.