I am having trouble running an HQL query in which i refer to the
right property of one of my persistent beans. Apparently, "right" is an HQL keyword, which i guess is the reason why my query won't run (details below), and besides, the same query works fine if i rename the
right property of my bean into something else.
I would like to avoid renaming my bean property, thus i'd like to know if there is a way (syntax?) to tell the HQL interpreter that the
right i'm using is not the keyword.
Details:
I have a class named Mandate with a property named
right which returns an object of type Right. I am performing the following HQL query (i am using Hibernate 3.0.5):
Code:
List mandates = session.createQuery (
"from " + Mandate.class.getName() + " where right is not null").list();
Attempting to run this query results in the following exception:
Code:
SEVERE: *** ERROR: line 1:38: unexpected token: right
org.hibernate.hql.ast.QuerySyntaxError: unexpected token: right near line 1, column 38 [from foo.bar.Mandate where right is not null]
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:63)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:215)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:127)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:427)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:884)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:834)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at be.smalsmvm.magma.dao.SearchMandatesDemo.main(SearchMandatesDemo.java:41)
Caused by: line 1:38: unexpected token: right
at org.hibernate.hql.antlr.HqlBaseParser.negatedExpression(HqlBaseParser.java:2032)
at org.hibernate.hql.antlr.HqlBaseParser.logicalAndExpression(HqlBaseParser.java:1937)
at org.hibernate.hql.antlr.HqlBaseParser.logicalOrExpression(HqlBaseParser.java:1901)
at org.hibernate.hql.antlr.HqlBaseParser.expression(HqlBaseParser.java:1663)
at org.hibernate.hql.antlr.HqlBaseParser.logicalExpression(HqlBaseParser.java:1834)
at org.hibernate.hql.antlr.HqlBaseParser.whereClause(HqlBaseParser.java:376)
at org.hibernate.hql.antlr.HqlBaseParser.queryRule(HqlBaseParser.java:617)
at org.hibernate.hql.antlr.HqlBaseParser.selectStatement(HqlBaseParser.java:263)
at org.hibernate.hql.antlr.HqlBaseParser.statement(HqlBaseParser.java:150)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:209)
... 7 more
Interestingly, this won't work either when i try to remove any ambiguity by aliasing the Mandate class and prefixing the
right property:
Code:
List mandates = session.createQuery (
"from " + Mandate.class.getName() + " as mandate where mandate.right is not null").list();
Code:
SEVERE: *** ERROR: line 1:46: unexpected token: .
org.hibernate.hql.ast.QuerySyntaxError: unexpected token: . near line 1, column 46 [from foo.bar.Mandate as mandate where mandate.right is not null]
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:63)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:215)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:127)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:427)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:884)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:834)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at be.smalsmvm.magma.dao.SearchMandatesDemo.main(SearchMandatesDemo.java:40)
Caused by: line 1:46: unexpected token: .
at org.hibernate.hql.antlr.HqlBaseParser.primaryExpression(HqlBaseParser.java:3327)
at org.hibernate.hql.antlr.HqlBaseParser.atom(HqlBaseParser.java:3031)
at org.hibernate.hql.antlr.HqlBaseParser.unaryExpression(HqlBaseParser.java:2806)
at org.hibernate.hql.antlr.HqlBaseParser.multiplyExpression(HqlBaseParser.java:2687)
at org.hibernate.hql.antlr.HqlBaseParser.additiveExpression(HqlBaseParser.java:2407)
at org.hibernate.hql.antlr.HqlBaseParser.concatenation(HqlBaseParser.java:481)
at org.hibernate.hql.antlr.HqlBaseParser.relationalExpression(HqlBaseParser.java:2195)
at org.hibernate.hql.antlr.HqlBaseParser.equalityExpression(HqlBaseParser.java:2057)
at org.hibernate.hql.antlr.HqlBaseParser.negatedExpression(HqlBaseParser.java:2020)
at org.hibernate.hql.antlr.HqlBaseParser.logicalAndExpression(HqlBaseParser.java:1937)
at org.hibernate.hql.antlr.HqlBaseParser.logicalOrExpression(HqlBaseParser.java:1901)
at org.hibernate.hql.antlr.HqlBaseParser.expression(HqlBaseParser.java:1663)
at org.hibernate.hql.antlr.HqlBaseParser.logicalExpression(HqlBaseParser.java:1834)
at org.hibernate.hql.antlr.HqlBaseParser.whereClause(HqlBaseParser.java:376)
at org.hibernate.hql.antlr.HqlBaseParser.queryRule(HqlBaseParser.java:617)
at org.hibernate.hql.antlr.HqlBaseParser.selectStatement(HqlBaseParser.java:263)
at org.hibernate.hql.antlr.HqlBaseParser.statement(HqlBaseParser.java:150)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:209)
... 7 more
Can someone help me make my query run without renaming my property?
Thanks in advance for your help!