What is wrong with this HQL query?

I encountered an error in sleep mode or I have an error that I cannot see:

select enty.number from EntityAliasName enty where enty.myId in ( select cons.myId from Consens cons where cons.number in ( select ord.number from Orders ord where ord.customer = :customer and ord.creationDate < ( select max(ord.creationDate) from Orders ord where ord.customer = :customer ) ) ) 

I get the following:

 org.hibernate.util.StringHelper.root(StringHelper.java:257) Caused by: java.lang.NullPointerException at org.hibernate.util.StringHelper.root(StringHelper.java:257) at org.hibernate.persister.entity.AbstractEntityPersister.getSubclassPropertyTableNumber(AbstractEntityPersister.java:1391) at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:54) at org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1367) at org.hibernate.hql.ast.tree.FromElement.getIdentityColumn(FromElement.java:320) 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:854) at org.hibernate.hql.antlr.HqlSqlBaseWalker.propertyRef(HqlSqlBaseWalker.java:1172) at org.hibernate.hql.antlr.HqlSqlBaseWalker.propertyRefLhs(HqlSqlBaseWalker.java:5167) at org.hibernate.hql.antlr.HqlSqlBaseWalker.propertyRef(HqlSqlBaseWalker.java:1133) at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:1993) at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:1932) at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1476) at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:580) at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:288) at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:231) 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:94) at org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:484) at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:394) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1341) 

using: Hibernate 3.3.2.GA/postgresql


Update:

I tried to fix the error, trying to complete each subtask for my own. I realized that I was getting the same exception by simply doing:

 select enty.number from EntityAliasName enty 

but if I do the following, this works:

 select number from EntityAliasName enty 

so now the question is, why?

Perhaps I should mention that EntityAliasName is an entity alias defined through:

 <class name="package.EntityName" table="entities" entity-name="EntityAliasName" mutable="false"> ... </class> 

Update 2:

I found a solution to the problem. My POJO was mapped as follows:

 <class name="package.EntityName" table="entities" entity-name="EntityAliasName" mutable="false"> <composite-id> <key-property name="val1" column="val1" type="long"/> <key-property name="val2" column="val2" type="integer"/> </composite-id> <property name="id" column="entity_id" type="string" length="255" not-null="true"/> ... </class> 

There is a problem with a composite identifier and using a property with the name id : HHH-1851 , reported by Anthony Patricio . Changing the property name from id to entityId solved the problem:

Thanks to mdma for pointing me in the right direction.

+4
source share
2 answers

I found a solution to the problem. My POJO was mapped as follows:

 <class name="package.EntityName" table="entities" entity-name="EntityAliasName" mutable="false"> <composite-id> <key-property name="val1" column="val1" type="long"/> <key-property name="val2" column="val2" type="integer"/> </composite-id> <property name="id" column="entity_id" type="string" length="255" not-null="true"/> ... </class> 

There is a problem with having a composite identifier and using a property with the name id : HHH-1851 , which is reported by Anthony Patricio . Changing the property name from id to entityId solved the problem:

 <property name="entityId" column="entity_id" type="string" length="255" not-null="true"/> 

Thanks to mdma for pointing me in the right direction.

just copied the answer from my update above to close it as an answer and keep up the reception ratio

+3
source

I was getting null by creating my entityManager in 1-2 hours, I don’t know why, and this post just solved my problem.

I had in one class (Java):

 @GeneratedValue private Long id; public Long getId() { return id; } 

I just read your post and changed it to:

  @JoinColumn(name = "id") @GeneratedValue private Long ide; public Long getId() { return ide; } 

And finally, a good compilation.

0
source

Source: https://habr.com/ru/post/1309990/


All Articles