[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-993?page=co...
]
Joachim Durchholz commented on HHH-993:
---------------------------------------
This is particularly annoying since SubqueryExpression#createAndSetInnerQuery's method
comment indicates that this is just prefetching data that it assumes will be needed
later.
And, yes, it just bit me. And I'm not going to comment on how long this has been lying
dormant.
Criteria subquery without projection fails throwing
NullPointerException
------------------------------------------------------------------------
Key: HHH-993
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-993
Project: Hibernate Core
Issue Type: Improvement
Components: core
Reporter: Johannes Rudolph
Priority: Minor
If you use a subquery in a criteria query and there is no projection, the execution of
the query will fail by throwing a NullPointerException:
Caused by: java.lang.NullPointerException
at
org.hibernate.loader.criteria.CriteriaQueryTranslator.getProjectedTypes(Crit
eriaQueryTranslator.java:298)
at
org.hibernate.criterion.SubqueryExpression.toSqlString(SubqueryExpression.ja
va:56)
at
org.hibernate.criterion.LogicalExpression.toSqlString(LogicalExpression.java
:39)
org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(Crit
eriaQueryTranslator.java:314)
...
I think it is expected behaviour that restrictions only work on 1-dimensional return
values of subqueries so it would be nice if Hibernate would mention that somewhere.
It would be nice if you could just write:
Criteria crit = dbSession.createCriteria(Bla.class);
DetachedCriteria detachedCrit = DetachedCriteria.forClass(Blub.class).add(
Restrictions.eq("condition", Boolean.FALSE));
crit.add( Restrictions.or( Restrictions.isNull("superBlub"),
Subqueries.in("superBlub", detachedCrit ) ) );
since Hibernate entities could be seen as "entities" so Hibernate should
automatically transform it into:
DetachedCriteria detachedCrit = DetachedCriteria.forClass(Blub.class).add(
Restrictions.eq("condition", Boolean.FALSE))
.setProjection( Projections.id() );
crit.add( Restrictions.or( Restrictions.isNull("superBlub"),
Subqueries.propertyIn("ueberPartner", detachedCrit ) ) );
--
This message is automatically generated by JIRA.
For more information on JIRA, see:
http://www.atlassian.com/software/jira