keywords as parameter names


Query worked fine using Hibernate 4.2.10
Query borked using Hibernate 4.2.12
query in question:
delete from com.mrbear.Transactionrelation trel where trel.timeperiod = :TIMEPERIOD and trel.krlObject = :OBJECT and not exists ( select '' from com.mrbear.Taxationtransaction tatr where tatr.transactionrelation.transactionRelationNr = trel.transactionRelationNr )

The problem disappears when I rename :OBJECT to :KRLOBJECT.

It is possible that OBJECT is a keyword in HQL and not allowed to be used, but why then did it work in the previous version of Hibernate (4.2.10)?

I hope you can reproduce it.


Hibernate 4.2.12/Java 7/JBoss AS 7.1.3 Final
Oracle Database 11g Enterprise Edition Release - 64bit Production


Maarten van Leunen
May 17, 2014, 8:26 PM

Thanks very much for the extensive explanation. I'll keep it in mind, when writing HQL queries.

Steve Ebersole
May 15, 2014, 10:00 PM

From Gail:

... need to get a list of reserved words, at least those that were affected by this bug.

I tried a couple of random tokens in hql.g and they did not cause a problem without the fix. Do you know what other than "class" and "OBJECT" would be affected? I did notice that things like "claSs" and "object" were also affected by by the bug, so case doesn't matter.

Did this bug only affect named parameters?

It should only affect named parameters, specifically named parameters whose name is recognized as something other than an IDENT in the lexer. This will be any tokens whose text is explicitly named in the grammar (the hql.g file). As an example, look at the difference in how the ALL (or OBJECT or CLASS) token is defined versus say the FIRST token:

This difference has an effect on the lexer. The lexer, based on the above declarations, will recognized the character sequence "all" (any case) as a token with type ALL (not IDENT!!!) and text "all". Whereas it will recognize the character sequence "first" as a token with type IDENT and text "first".

Using "all" or "object" or "class" (or any other "token literals") as a named parameter name will trigger this; meanwhile, using ":first" as a named parameter should be fine. So look through hql.g and find all the defined tokens that assign a text literal... those are the words that will trigger this if used as a named parameter name. There are some others, but this rule covers most cases.

Steve Ebersole
May 15, 2014, 2:44 PM

For reasons I cannot fully explain, adding the semantic predicates to the atom rule caused the prediction checks in the generated parser to be very different. As far as I can tell our use of k=3 in the grammar also comes into play as the predictions were checking 3 tokens out. The end result being that after COLON the parser was always looking specifically for IDENT (not allowing for keyword-turned-ident). Moving the semantic predicates (and therefore recognition of CAST/FUNCTION) to primaryExpression instead fixed the problem.

This part of the grammar (atom/primaryExpression and related sub-rules) is a mess imo. It tries to generically handle too many cases. However refactoring them to be more readable would require major changes and is best left for the new parser

Gail Badner
May 13, 2014, 11:10 PM

15:31:41,973 DEBUG QueryTranslatorImpl:267 - parse() - HQL: from org.hibernate.test.hql.Human h where = :OBJECT
15:31:41,973 ERROR ErrorCounter:54 - line 1:52: unexpected token: :
15:31:41,973 ERROR ErrorCounter:50 - line 1:52: unexpected token: :
line 1:52: unexpected token: :
at org.hibernate.hql.internal.antlr.HqlBaseParser.atom(
at org.hibernate.hql.internal.antlr.HqlBaseParser.unaryExpression(
at org.hibernate.hql.internal.antlr.HqlBaseParser.multiplyExpression(
at org.hibernate.hql.internal.antlr.HqlBaseParser.additiveExpression(
at org.hibernate.hql.internal.antlr.HqlBaseParser.concatenation(
at org.hibernate.hql.internal.antlr.HqlBaseParser.relationalExpression(
at org.hibernate.hql.internal.antlr.HqlBaseParser.equalityExpression(
at org.hibernate.hql.internal.antlr.HqlBaseParser.negatedExpression(
at org.hibernate.hql.internal.antlr.HqlBaseParser.logicalAndExpression(
at org.hibernate.hql.internal.antlr.HqlBaseParser.logicalOrExpression(
at org.hibernate.hql.internal.antlr.HqlBaseParser.expression(
at org.hibernate.hql.internal.antlr.HqlBaseParser.logicalExpression(
at org.hibernate.hql.internal.antlr.HqlBaseParser.whereClause(
at org.hibernate.hql.internal.antlr.HqlBaseParser.queryRule(
at org.hibernate.hql.internal.antlr.HqlBaseParser.selectStatement(
at org.hibernate.hql.internal.antlr.HqlBaseParser.statement(
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(
at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(
at org.hibernate.internal.AbstractSessionImpl.createQuery(
at org.hibernate.internal.SessionImpl.createQuery(
at org.hibernate.test.hql.ASTParserLoadingTest.testObjectAsParameter(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
at org.junit.runners.model.FrameworkMethod.invokeExplosively(
at org.hibernate.testing.junit4.ExtendedFrameworkMethod.invokeExplosively(
at org.junit.internal.runners.statements.InvokeMethod.evaluate(
at org.junit.internal.runners.statements.RunBefores.evaluate(
at org.junit.internal.runners.statements.RunAfters.evaluate(
at org.junit.internal.runners.statements.FailOnTimeout$

Gail Badner
May 13, 2014, 11:06 PM

I've added 2 tests to ASTParserLoadingTest that reproduce this issue: testClassAsParameter() (using a parameter name "class"), and testClassAsParameter() (using a parameter named "OBJECT").

It's been pushed to 4.2, 4.3, and master.

On 4.2, it was introduced by the first commit for HHH-9100: 6cef805a328c7490671f82c8390cc37b79b188ce .



Steve Ebersole


Maarten van Leunen

Fix versions



Suitable for new contributors


Requires Release Note


Pull Request





Affects versions