We're updating the issue view to help you get more done. 

Cannot dereference a CompositeUserType property named "on"

Description

A CompositeUserType property named "on" cannot be dereferenced in an HQL query.

Code, mappings, and an HSQL for the following examples is in the attached tarball. That attachment includes a test script that demonstrates the problem. You can run it like so:

ant -Dhibernate-path=/path/to/hibernate-3.1

Mapping used:
<class name="Cat" table="t_cats">
<id name="id"><generator class="identity"/></id>
<property name="name"/>
<property name="entered" type="eg.domain.hibernate.AuditInfoType">
<column name="entered_on"/>
<column name="entered_by"/>
</property>
</class>

AuditInfoType is a CompositeUserType that defines two properties: on and by.

The test fails when it runs the following query:

select c.entered.on from Cat c

It fails with this exception:

org.hibernate.hql.ast.QuerySyntaxException: unexpected token: . near line 1, column 17 [select c.entered.on from eg.domain.Cat c]
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:244)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:155)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:105)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:75)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:134)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:113)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1600)
at eg.Main.main(Main.java:33)
Caused by: line 1:17: unexpected token: .
at org.hibernate.hql.antlr.HqlBaseParser.primaryExpression(HqlBaseParser.java:877)
at org.hibernate.hql.antlr.HqlBaseParser.atom(HqlBaseParser.java:3422)
at org.hibernate.hql.antlr.HqlBaseParser.unaryExpression(HqlBaseParser.java:3200)
at org.hibernate.hql.antlr.HqlBaseParser.multiplyExpression(HqlBaseParser.java:3082)
at org.hibernate.hql.antlr.HqlBaseParser.additiveExpression(HqlBaseParser.java:2802)
at org.hibernate.hql.antlr.HqlBaseParser.concatenation(HqlBaseParser.java:570)
at org.hibernate.hql.antlr.HqlBaseParser.relationalExpression(HqlBaseParser.java:2586)
at org.hibernate.hql.antlr.HqlBaseParser.equalityExpression(HqlBaseParser.java:2449)
at org.hibernate.hql.antlr.HqlBaseParser.negatedExpression(HqlBaseParser.java:2413)
at org.hibernate.hql.antlr.HqlBaseParser.logicalAndExpression(HqlBaseParser.java:2331)
at org.hibernate.hql.antlr.HqlBaseParser.logicalOrExpression(HqlBaseParser.java:2296)
at org.hibernate.hql.antlr.HqlBaseParser.expression(HqlBaseParser.java:2082)
at org.hibernate.hql.antlr.HqlBaseParser.aliasedExpression(HqlBaseParser.java:2249)
at org.hibernate.hql.antlr.HqlBaseParser.selectedPropertiesList(HqlBaseParser.java:1455)
at org.hibernate.hql.antlr.HqlBaseParser.selectClause(HqlBaseParser.java:1365)
at org.hibernate.hql.antlr.HqlBaseParser.selectFrom(HqlBaseParser.java:1106)
at org.hibernate.hql.antlr.HqlBaseParser.queryRule(HqlBaseParser.java:702)
at org.hibernate.hql.antlr.HqlBaseParser.selectStatement(HqlBaseParser.java:296)
at org.hibernate.hql.antlr.HqlBaseParser.statement(HqlBaseParser.java:159)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:238)
... 9 more

A similar exception is thrown when entered.on is used in a where clause. Selecting for entered.by works fine, as does loading an entire Cat instance. If you change the name of the "on" property in AuditInfoType, the problem goes away.

Environment

3.1.1, database independent

Status

Assignee

Unassigned

Reporter

Rhett Sutphin

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

3.0.5
3.1.1

Priority

Major