After having tried a bit with the following statement i found out that the position of the exists clause seems to be relevant for hibernate:
Code:
@NamedQuery (
name=ModuleSubscription.QUERY_FIND_SUBSCRIBERS,
query=
"select ms.subscriber from ModuleSubscription as ms where " +
" ms.subscriber.active = true and " +
" exists (select 1 from PersonToe as pt where pt.person = ms.subscriber and pt.toe = :toe) and " +
"((ms.codeNumber.kgValue = :kgValue and ms.codeNumber.kguValue is null and ms.codeNumber.enValue is null) or " +
" (ms.codeNumber.kgValue = :kgValue and ms.codeNumber.kguValue is :kguValue and ms.codeNumber.enValue is null) or " +
" (ms.codeNumber.kgValue = :kgValue and ms.codeNumber.kguValue is :kguValue and ms.codeNumber.enValue is :enValue)) "
)
produces this stacktrace:
java.lang.NullPointerException
at org.hibernate.hql.ast.tree.FromClause.findIntendedAliasedFromElementBasedOnCrazyJPARequirements(FromClause.java:120)
at org.hibernate.hql.ast.tree.FromClause.getFromElement(FromClause.java:107)
at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:81)
at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:255)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3056)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2945)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.collectionFunctionOrSubselect(HqlSqlBaseWalker.java:4253)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3968)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1762)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1690)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1687)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:776)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:577)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:228)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
But this statement works:
Code:
@NamedQuery (
name=ModuleSubscription.QUERY_FIND_SUBSCRIBERS,
query=
"select ms.subscriber from ModuleSubscription as ms where " +
" exists (select 1 from PersonToe as pt where pt.person = ms.subscriber and pt.toe = :toe) and " +
" ms.subscriber.active = true and " +
"((ms.codeNumber.kgValue = :kgValue and ms.codeNumber.kguValue is null and ms.codeNumber.enValue is null) or " +
" (ms.codeNumber.kgValue = :kgValue and ms.codeNumber.kguValue is :kguValue and ms.codeNumber.enValue is null) or " +
" (ms.codeNumber.kgValue = :kgValue and ms.codeNumber.kguValue is :kguValue and ms.codeNumber.enValue is :enValue)) "
)
I tried with jboss 4.2.2 and 4.2.3 (hibernate: 3.2.4.sp1)
So could this be a hibernate bug or am i doing things wrong?
(I didnt find a related jira on my own)
Regards!