I'm using a simple named query to search for all objects that have a given value-element in a set. It works if I alias the object, but not if I don't. In the code below, query OrganisationsByType1 produces the given exception, OrganisationsByType2 works perfectly.
I've done a quick search through this forum and through JIRA, but I couldn't find anything like this. Does anyone know if this has been fixed, or even if there's a JIRA issue about it that I missed? I am using a fairly old version of hibernate, and I don't expect any fix to be applied to 3.0.5 since there's such an easy workaround, but it should be fixed in future versions.
Hibernate version: 3.0.5
Mapping documents:Code:
<class name="OrganisationImpl" table="Organisation">
...
<set name="Types" table="OrganisationTypeLink" lazy="true" cascade="all">
<key column="OrganisationID"/>
<element column="OrganisationTypeID" not-null="true"
type="OrganisationType"/>
</set>
</class>
<query name="OrganisationsByType1">
from OrganisationImpl
where :Type in elements(Types)
</query>
<query name="OrganisationsByType2">
from OrganisationImpl o
where :Type in elements(o.Types)
</query>
Full stack trace of any exception that occurs:Code:
java.lang.NullPointerException
at org.hibernate.hql.ast.MethodNode.handleElements(MethodNode.java:154)
at org.hibernate.hql.ast.MethodNode.resolveCollectionProperty(MethodNode.java:105)
at org.hibernate.hql.ast.CollectionFunction.resolve(CollectionFunction.java:22)
at org.hibernate.hql.ast.HqlSqlWalker.processFunction(HqlSqlWalker.java:538)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.collectionFunction(HqlSqlBaseWalker.java:2273)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.collectionFunctionOrSubselect(HqlSqlBaseWalker.java:3937)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.inRhs(HqlSqlBaseWalker.java:3854)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3517)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1405)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1333)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:599)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:404)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:201)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:151)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:427)
at org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:388)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:291)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1005)
...