]
Anthony Whitford commented on HHH-158:
--------------------------------------
I've hit this issue using Hibernate version 3.2.5.ga. Has anyone made progress since
the previous update 4 years ago?
nested DetachedCriteria throwing NullPointerException
-----------------------------------------------------
Key: HHH-158
URL:
https://hibernate.onjira.com/browse/HHH-158
Project: Hibernate ORM
Issue Type: Bug
Components: core
Affects Versions: 3.0 beta 4
Reporter: Jérôme Boehm
Assignee: Gavin King
Attachments: testcase.zip
It seems that it is not possible to nest DetachedCriteria.
This is examplified in the testWithReturnedObject() method of the attached TestCase.
When nesting DetachedCriteria using
DetachedCriteria.add(Subqueries.<a_Subqueries_static_method>) twice, we get the
following exception:
java.lang.NullPointerException
at
org.hibernate.criterion.SubqueryExpression.getTypedValues(SubqueryExpression.java:73)
at
org.hibernate.loader.criteria.CriteriaQueryTranslator.getQueryParameters(CriteriaQueryTranslator.java:230)
at org.hibernate.criterion.SubqueryExpression.toSqlString(SubqueryExpression.java:50)
at org.hibernate.criterion.Junction.toSqlString(Junction.java:58)
at
org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:312)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:92)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1208)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:299)
at test.subqueries.SubqueriesTest.main(SubqueriesTest.java:41)
Then, after "correcting" SubqueryExpression so that the params instance
variable is initialized (see the attached Corrected_SubqueryExpression), it seems that the
nested aliases are not properly propagated, which is examplified in
testWithNoReturnedObject().
The generated sql is:
select this_.a_id as a1_0_ from a this_ where exists (select this0__.b_id as y0_ from b
this0__ where this0__.a_id=this_.a_id and exists (select this0__.c_id as y0_ from c
this0__ where this0__.b_id=this0__.b_id))
I think it should be (notice the this1__ alias for table c):
select this_.a_id as a1_0_ from a this_ where exists (select this0__.b_id as y0_ from b
this0__ where this0__.a_id=this_.a_id and exists (select this1__.c_id as y0_ from c
this1__ where this1__.b_id=this0__.b_id))
--
This message is automatically generated by JIRA.
For more information on JIRA, see: