I have an entity with a derived property that maps to an entity with a composite key.
Here is my mapping (using annotations) inside SampleEntity:
@OneToOne(fetch = FetchType.LAZY)
@JoinColumnsOrFormulas({
@JoinColumnOrFormula(formula =
@JoinFormula(value = "sql comes here", referencedColumnName = "COLUMN_A")),
@JoinColumnOrFormula(formula =
@JoinFormula(value = "sql comes here", referencedColumnName = "COLUMN_B"))
})
public MyEntity getMyEntity() {
return myEntity;
}
MyEntity contains a composite key (with properties that maps to COLUMN_A and COLUMN_B).
It works great when I call getMyEntity() on the SampleEntity (I retrieves the correct entity object as I would expect).
The problem comes in when I use it in a HQL query.
Example:
from SampleEntity where myEntity.id.propertyName = ?
I get the following stacktrace:
java.lang.NullPointerException at org.hibernate.persister.entity.AbstractPropertyMapping.toColumns(AbstractPropertyMapping.java:103) at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:62) at org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1443) at org.hibernate.hql.ast.tree.FromElementType.toColumns(FromElementType.java:354) at org.hibernate.hql.ast.tree.FromElementType.toColumns(FromElementType.java:323) at org.hibernate.hql.ast.tree.FromElement.toColumns(FromElement.java:491) at org.hibernate.hql.ast.tree.DotNode.getColumns(DotNode.java:133) at org.hibernate.hql.ast.tree.DotNode.initText(DotNode.java:252) at org.hibernate.hql.ast.tree.DotNode.resolve(DotNode.java:246) at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:117) at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:113) at org.hibernate.hql.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:866) at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1321) at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4383) at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3856) at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1907) at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:822) at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:608) at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:292) at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:235) at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:254) at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185) at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136) at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:101) at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:80) at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:98) at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156) at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135) at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1760) ...
Anyone have an idea what might be the problem? As far as I know it should be OK to used derived properties in queries, or am I mistaken? Is it the composite key that is causing this?
I am using Hibernate and Hibernate-annotations version 3.5.1-Final.