Hi,
We have come across an issue with the usage of nested subselects in the sql query with hibernate 3.2.5.
We get the following exception when there is more than one level of sub-selects in the query :
----------------------------------------------------------------------------------------------------------------------
java.lang.NullPointerException
at org.hibernate.criterion.SubqueryExpression.getTypedValues(SubqueryExpression.java:80)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getQueryParameters(CriteriaQueryTranslator.java:251)
at org.hibernate.criterion.SubqueryExpression.toSqlString(SubqueryExpression.java:55)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:334)
at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:71)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:67)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1550)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at NestedDetachedCriteriaTest.testNestedDetachedCriteria(Unknown Source)
----------------------------------------------------------------------------------------------------------------------
The actual query that gets fired is like:
----------------------------------------------------------------------------------------------------------------------
select this_.name as y0_ from cat this_ where this_.name =
(select this0_.name as y0 from cat this0__ where this0__.parent_id =
(select this0_.parent_id as y0 from cat this0__ where this0__.name =
(select this0_.name as y0 from cat this0__ where this0__.cat_id = ?)))
----------------------------------------------------------------------------------------------------------------------
We investigated the issue and have fixed it by making some changes in org.hibernate.criterion.SubqueryExpression class.
The attached file has the following contents:
1. SubqueryExpression.java - Fix we have made to SubqueryExpression class.
2. NestedDetachedCriteriaTest.zip - A test case to highlight the nested sub-select issue (testNestedDetachedCriteria).
Regards,
Roshan
Hibernate 3.2.5, Oracle 10g
Thank you for fixing this bug. It has been driving me crazy for weeks and I couldn't figure out what I was doing wrong. Is this fix included in the latest version of Hibernate. What is the best way to apply it if it's not included in the latest version? Any chance you can email me the full hibernate library (jvence at gmail) - Many thanks for fixing this....
This patch is calling function: dialect.getForReadOnlyString() that is not available in Hibernate 2.5.x or 3.3.1. Is this DB specific? I'm trying to use this with mysql 5.
Bulk closing stale resolved issues