Hibernate Books

All times are UTC - 5 hours [ DST ]

Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: HQL unexpected token on using column named "properties"
PostPosted: Tue Jan 03, 2017 12:31 pm 

Joined: Tue Jan 03, 2017 12:14 pm
Posts: 1
Hi all,

we are using Hibernate 4.2.21_FINAL and we defined a named query

@javax.persistence.NamedQuery (name = "Position.getByProperties", query = "select var from T_POSITION var WHERE var.properties=0")

in our entity.
The startup already fails with the following exception:

03.01.2017 17:24:47.123 ERROR [ErrorCounter] line 1:72: unexpected token: var
line 1:72: unexpected token: var
at org.hibernate.hql.internal.antlr.HqlBaseParser.primaryExpression(HqlBaseParser.java:991)
at org.hibernate.hql.internal.antlr.HqlBaseParser.atom(HqlBaseParser.java:3493)
at org.hibernate.hql.internal.antlr.HqlBaseParser.unaryExpression(HqlBaseParser.java:3271)
at org.hibernate.hql.internal.antlr.HqlBaseParser.multiplyExpression(HqlBaseParser.java:3143)
at org.hibernate.hql.internal.antlr.HqlBaseParser.additiveExpression(HqlBaseParser.java:2848)
at org.hibernate.hql.internal.antlr.HqlBaseParser.concatenation(HqlBaseParser.java:590)

org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: var near line 1, column 72 [select var from com.syncrotess.gen.model.jpa.PositionJpaImpl var WHERE var.properties=0]
at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
at org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:79)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:278)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:182)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:138)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:104)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:79)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168)

The problem only occurs if the property is named "properties". I know that "properties" is a HQL keywords token but I wonder why this one now actually fails, others like "count" work. Is this problem known, is it fixed in newer versions of Hibernate? Or can I escape it somehow? What other keywords cause this problem?


 Post subject: Re: HQL unexpected token on using column named "properties"
PostPosted: Mon Jan 09, 2017 6:51 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1038
HQL defines the following syntax:

fetch all properties

Therefore, the properties keyword is reserved and you can't use it in HQL. What you need to do is rename the "properties" attribute to something else, like "propertyList".

If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.