|
This issue is quite old. There is good reason to question whether the issue is still present.
I tried to create a test case against hibernate 4.3.0-Final, but instead of a broken SQL query I got a NullPointerException while generating the query.
I won't add it to the case yet, as it is not demonstrating the reported bug. I can post a few lines here insted.
In this test, Issue has a unidirectional ManyToOne mapping "reporter" to User, and we want to find users that have reported issues that are awaiting a test case:
final User brett = new User("Brett Meyer"); session.persist(brett); final User eirik = new User("Eirik Maus"); session.persist(eirik);
session.persist(new Issue(eirik, "hhhh-3435", "awaiting testcase")); session.persist(new Issue(eirik, "hhhh-2852", "closed"));
session.flush(); session.clear();
Criteria criteria = session.createCriteria(User.class); DetachedCriteria subquery = DetachedCriteria.forClass(Issue.class); subquery.add(Restrictions.eq("state", "awaiting testcase")); subquery.add(Restrictions.eqProperty("reporter.id", "this.id")); criteria.add(Subqueries.exists(subquery)); assertThat(criteria.list().size(), is(1));
The crash is inside the sql generation for detached query: It looks like the root criteria set doesn't have any project, so getting the rootCriteria projection's types result in NPE:
java.lang.NullPointerException at org.hibernate.loader.criteria.CriteriaQueryTranslator.getProjectedTypes(CriteriaQueryTranslator.java:399) at org.hibernate.criterion.SubqueryExpression.createAndSetInnerQuery(SubqueryExpression.java:152) at org.hibernate.criterion.SubqueryExpression.toSqlString(SubqueryExpression.java:78) at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:417) at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:123) at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:92) at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:97) at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1659) at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:380) at hibernate.issues.hhhh3534.Hhhh3534Test.detachedQueryShouldNotUse_thisAsQueryAlias(Hhhh3534Test.java:69)
— Maybe it's just easier to add a line to the documentation of DetachedCriteria.forClass(Some.class) that the user is adviced to use the other method, and specify a different alias than "this_".
|