-->
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.  [ 4 posts ] 
Author Message
 Post subject: SELECT clause in FROM clause in Hibernate
PostPosted: Thu Aug 11, 2005 7:25 am 
Newbie

Joined: Sat Jul 30, 2005 7:44 am
Posts: 15
Hi everybody!

I am using hibernate3.0 to retrieve data from database. But I am facing problem in using select clause in From clause. for example:

Code:
select

sum(sTotal) + sum(Disc) as Total

From (
select disc.sDiscount as Disc from discount as disc,
select pos.Total as sTotal from PosTables as pos
)



This query is not original one but it will use select clause in from clause, as it is given above. I have doubt tht this functionlity is not supported in hibernate.Please let me know whether such query is possible in HQL or not . Thanks in advance


Top
 Profile  
 
 Post subject: Re: SELECT clause in FROM clause in Hibernate
PostPosted: Thu Aug 11, 2005 9:28 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
Have you tried running this ? What results do you get ?

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 9:37 am 
Newbie

Joined: Sat Jul 30, 2005 7:44 am
Posts: 15
Hi preston, thanks for replying I tried to run it but I am getting

unexpected token: select org.hibernate.hql.ast.QuerySyntaxError: unexpected token: select near line 1, column 31

Does hibernate query support select clause in from clause? any help will be greatly appreciated


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 1:09 pm 
Regular
Regular

Joined: Thu Sep 04, 2003 10:43 am
Posts: 61
Does hibernate query support select clause in from clause? any help will be greatly appreciated[/quote]

I've a similar problem and I workarounded this way:

String sqlQuery = "SELECT COUNT(*) FROM ( " +
myClass.translateHQL2SQL( innerQuery ) +
" )";

And then executed as a SQL query.

and to translate HQL to SQL you can you something like:

ASTQueryTranslatorFactory cqt = new ASTQueryTranslatorFactory();
QueryTranslator qt = cqt.createQueryTranslator(HQL, new HashMap(), (SessionFactoryImplementor)sf);
qt.compile(new HashMap(), false );
String result = qt.getSQLString();

Of course, I will appreciate to write it all in HQL, but Hibernate do not compile such a query.
Hope this helps.


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

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.