-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: HQL Parser for dot-qualified names context-dependent ?!?
PostPosted: Tue May 02, 2006 10:45 am 
Newbie

Joined: Tue Jan 17, 2006 1:06 pm
Posts: 2
How just found this and wondered whether this is expected behavior or a bug. Being expected behavior this should have been at least reminded with strong red in documentation, while is somehow counterintuitiv.

So imagine two tables

CARD:
primary key:
GUID
other fields:
name -- string
state -- string

PAYMENT
primary key:
card(foreign key to CARD through GUID)
payment_time -- timestamp
other fields:
...

I do hibernate query against PAYMENT:

session.createQuery("from PAYMENT where id.card.name = 'KAWAPONGA'").list()

does work ok.
Then try

session.createQuery("from PAYMENT where id.card.state = 'OK'").list()

works either.
BUT! try the both conditions combined:

session.createQuery("from PAYMENT where id.card.name = 'KAWAPONGA' and id.card.state = 'OK'").list()

And you'll get the
RuntimeException in...
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:223)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:156)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:103)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:473)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1060)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1010)
...
Caused by: Invalid path: 'id.card.state'
at org.hibernate.hql.ast.util.LiteralProcessor.lookupConstant(LiteralProcessor.java:93)
at org.hibernate.hql.ast.tree.DotNode.resolve(DotNode.java:178)
at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:94)
at org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:90)
at org.hibernate.hql.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:626)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1215)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4024)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3872)


Wow, this looks already weird. But try then

session.createQuery("from PAYMENT where id.card.name = 'KAWAPONGA' and state = 'OK'").list()

... and you'll get no exception.

It seems the parser, that parses these dot-qualified names keeps the state of the last id parsed, so the further id are counted in virtually the same namespace as the last id parsed (so it is like with directories descent down but forgot to jump up afterwards)? The normal behavior to be expected is that the namespace is always root namespace unless somehow specified otherwise, isn't it?

With table names explicitly specified, e.g.
session.createQuery("from PAYMENT p where p.id.card.name = 'KAWAPONGA' and p.id.card.state = 'OK'").list()
.. there is no problem.

Hibernate version:
tried with 3.1

Some comments on this behavior?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.