This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Object Relational Mapping and the fly likes subquery sql to hql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "subquery sql to hql" Watch "subquery sql to hql" New topic
Author

subquery sql to hql

nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
How can I express this sql in hql?:

SQL:



I have tried it with this HQL, but it s failed because of "org.hibernate.hql.ast.QuerySyntaxException: unexpected token":


any ideas?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

HQL does not support union. Just use two queries.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
nimo frey
Ranch Hand

Joined: Jun 28, 2008
Posts: 580
oh okay,

hmm and what about this kind of subquery:

SQL:


in HQL??

naveen velicheti
Greenhorn

Joined: Apr 02, 2010
Posts: 8
Hey I have the same problem

Did you get this resolved

This is a sample query
"select r1.roleId from (select r1.roleId from Roles r1)r1" (I have much complex query than this)


I get this as error when I run the above


Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 1, column 22 [select r1.roleId from (select r1.roleId from com.jci.bots.data.Roles r1)r1]
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:31)
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:24)
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:258)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:157)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
at com.jci.hibernate.HibernateDAO.getQueryResultList(HibernateDAO.java:179)
... 1 more

Can you tell me why it is not working
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: subquery sql to hql