Annotated Hibernate Entity can not have a Bean property as ID (literal id)

Description

the annotated entity has property name as "id", but it is not a identity property.
When using hibernate to create a simple query again the entity as
"Select MyEntity_Alias from MyEntity MyEntity_Alias"
Then the hibernate give out the following exception:

java.lang.NullPointerException
null
at org.hibernate.util.StringHelper.root(StringHelper.java:260)
at org.hibernate.persister.entity.AbstractEntityPersister.getSubclassPropertyTableNumber(AbstractEntityPersister.java:1467)
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.FromElement.getIdentityColumn(FromElement.java:345)
at org.hibernate.hql.ast.tree.IdentNode.resolveAsAlias(IdentNode.java:154)
at org.hibernate.hql.ast.tree.IdentNode.resolve(IdentNode.java:100)
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:867)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.propertyRef(HqlSqlBaseWalker.java:1199)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:2047)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:1983)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1515)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:586)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:294)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:237)
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.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.HQLQueryPlan.<init>(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)
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:47)

Step to reproduce

Using the attach Annotated entity bean file SimpleAnnotation.java
and run the FirstExample.java (both file are attached)

Environment

Hibernate 3.5.3 final, with hsql as database

Activity

Show:
Brett Meyer
October 2, 2013, 5:14 PM

This has nothing to do with the property being named a literal "id". Your query is incorrect. "Select" needs to identify individual properties, aggregate functions, etc. To select all columns, use "from SimpleAnnotation". W/ that query, it works fine.

Assignee

Brett Meyer

Reporter

yaodonghu

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Minor
Configure