
| Key: |
HHH-993
|
| Type: |
Improvement
|
| Status: |
Open
|
| Priority: |
Minor
|
| Assignee: |
Unassigned
|
| Reporter: |
Johannes Rudolph
|
| Votes: |
12
|
| Watchers: |
6
|
|
If you were logged in you would be able to see more operations.
|
|
|
|
Issue Links:
|
Relates
|
|
This issue relates to:
|
|
|
HHH-158 nested DetachedCriteria throwing NullPointerException
|
|
|
|
|
|
|
|
|
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 ) ) );
|
|
Description
|
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 ) ) ); |
Show » |
|
Subqueries.propertyIn("superBlub", detachedCrit ) ) );