"org.hibernate.QueryException: could not resolve property: null ..." in Hibernate
Issue
-
An entity is defined with a composite (multi-property) identifier/key
@Entity(name = "Person") @IdClass(PersonId.class) public static class Person implements Serializable { @Id private String name; @Id private int index; private Integer id; }
-
Executing a query against the
id
property:s.createQuery( "from Person p where p.id is null", Person.class ).list();
-
An exception is raised
... org.hibernate.QueryException: could not resolve property: null of: org.test.entities.Person at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:73) at org.hibernate.persister.entity.AbstractPropertyMapping.toColumns(AbstractPropertyMapping.java:88) at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:43) at org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1952) at org.hibernate.hql.internal.ast.tree.FromElementType.toColumns(FromElementType.java:442) at org.hibernate.hql.internal.ast.tree.FromElementType.toColumns(FromElementType.java:408) at org.hibernate.hql.internal.ast.tree.FromElement.toColumns(FromElement.java:513) at org.hibernate.hql.internal.ast.tree.FromElement.getIdentityColumns(FromElement.java:344) at org.hibernate.hql.internal.ast.tree.IdentNode.resolveAsAlias(IdentNode.java:198) at org.hibernate.hql.internal.ast.tree.IdentNode.resolve(IdentNode.java:124) at org.hibernate.hql.internal.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:1045) at org.hibernate.hql.internal.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:1033) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.addrExpr(HqlSqlBaseWalker.java:5080) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.addrExprLhs(HqlSqlBaseWalker.java:5614) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.addrExpr(HqlSqlBaseWalker.java:4987) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1286) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4706) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:4174) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2138) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:815) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:609) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:313) at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:261) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:271) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:191) ...
Environment
- Red Hat JBoss Enterprise Application Platform (EAP) 7
- Hibernate 5
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.