HQL doesn't allow '$' as the leading character for property names

Description

HQL Query example:

select distinct user.party from com.itf.iceclaims.domain.party.user.UserImpl user inner join user.party.$RelatedWorkgroups relatedWorkgroups where relatedWorkgroups.workgroup.id = :workgroup and relatedWorkgroups.effectiveTime.start <= :datesnow and relatedWorkgroups.effectiveTime.end > :dateenow

Stack Trace:

Caused by: org.hibernate.QueryException: unexpected char: '$' [select distinct user.party from com.itf.iceclaims.domain.party.user.UserImpl user inner join user.party.$RelatedWorkgroups relatedWorkgroups where relatedWorkgroups.workgroup.id = :workgroup and relatedWorkgroups.effectiveTime.start <= :datesnow and relatedWorkgroups.effectiveTime.end > :dateenow]
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:190)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:103)
at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:72)
at org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:52)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:108)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:88)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.springframework.orm.hibernate3.HibernateTemplate$CloseSuppressingInvocationHandler.invoke(HibernateTemplate.java:1178)
at $Proxy195.createQuery(Unknown Source)
at com.itf.iceclaims.dao.party.user.UserDaoHibernateImpl$2.doInHibernate(UserDaoHibernateImpl.java:85)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:365)
... 55 more
Caused by: line 1:105: unexpected char: '$'
at org.hibernate.hql.antlr.HqlBaseLexer.nextToken(HqlBaseLexer.java:278)
at antlr.TokenBuffer.fill(TokenBuffer.java:69)
at antlr.TokenBuffer.LA(TokenBuffer.java:80)
at antlr.LLkParser.LA(LLkParser.java:52)
at org.hibernate.hql.ast.HqlParser.weakKeywords(HqlParser.java:281)
at org.hibernate.hql.antlr.HqlBaseParser.path(HqlBaseParser.java:542)
at org.hibernate.hql.antlr.HqlBaseParser.fromJoin(HqlBaseParser.java:1705)
at org.hibernate.hql.antlr.HqlBaseParser.fromClause(HqlBaseParser.java:1420)
at org.hibernate.hql.antlr.HqlBaseParser.selectFrom(HqlBaseParser.java:1130)
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:236)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:153)
... 69 more

Propsed/Working Solution:

Update the 'hql.g' grammer file, lines 780 to 792, with the following code fragment. (I have moved the '$' character from the ID_LETTER to the ID_START_LETTER):

protected
ID_START_LETTER
: '_'

'a'..'z'

'\u0080'..'\ufffe' // : Allow unicode chars in identifiers

'$'
;

protected
ID_LETTER
: ID_START_LETTER

'0'..'9'
;

Environment

Hibernate 3.1-rc3; Windows; JDK1.5.0; SQLSerer2ksp4

Activity

Show:
Christian Bauer
December 9, 2005, 1:17 PM

Everybody else on the planet uses the "private" keyword for private fields.

Joshua Davis
December 9, 2005, 2:24 PM

Fixed in HEAD.

Dean Arnold
December 9, 2005, 2:29 PM

With all due respect Christian, these are persisted fields being mapped by hibernate. These are not 'private' fields only used within the implementation class, although we do not wish to promote their usage through their interface/api.

Fields prefixed with a '$' character, like the '_' character, are supported by the sun naming standards and I hope they would be supported by hibernate.

Dean Arnold
December 9, 2005, 2:30 PM

Thanks guys!!!! Only saw your fixed comment after posting my last comment.

Many Thanks

Steve Ebersole
March 21, 2011, 6:59 PM

Closing stale resolved issues

Fixed

Assignee

Joshua Davis

Reporter

Dean Arnold

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure