Using Nested DetachedCriteria (Sub-Selects) throwing NullPointerException

Description

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

Environment

Hibernate 3.2.5, Oracle 10g

Activity

Show:
Jean Vence
October 12, 2008, 8:24 PM

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....

Jean Vence
October 12, 2008, 9:06 PM

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.

Steve Ebersole
March 22, 2011, 6:06 AM

Bulk closing stale resolved issues

Duplicate

Assignee

Diego Plentz

Reporter

Roshan Dawrani

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Major