-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to replicate this SQL querry
PostPosted: Thu Jul 31, 2008 2:51 pm 
Newbie

Joined: Thu Jul 31, 2008 2:43 pm
Posts: 2
How will i be able to replicate the following SQLquerry in hibernate.

SQL Querry
-------------
select main2.ID_ as ID from
(select distinct fv.Order_ID from order_functvalinstance fv where (fv.FUNCTION_= 'ABC' and fv.VALUE_ = '123' ) ) as main,

(select distinct fv.Order_ID from order_functvalinstance fv where (fv.FUNCTION_= 'xyz' and fv.VALUE_ = '891' ) ) as main2

where main.ID_=main2.ID_

_________________
Celebrating Querying,
JagadeshK


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 31, 2008 4:44 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Once you get your objects mapped, I think the Criteria API will make this a very easy request to implement:

How to Use the Hibernate Criteria API: A Simple Tutorial

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject: Re:How to replicate this SQL querry
PostPosted: Mon Aug 04, 2008 12:42 pm 
Newbie

Joined: Thu Jul 31, 2008 2:43 pm
Posts: 2
Hi Cameron McKenzie,
Thanks for your input. I am new to Hibernate so i dint try new ways.
I did the following and landed in Exception.

(A)I got my objects mapped,
(B) I tried to use the usual SQL like querry structure to feed the Hibernate.


I did something like this....

Query selectQuery = session.createQuery("select main.id from (select distinct fc.function , fc.id from com.exe.Function fc where fc.function='Add') main");

But i land up in exception as below....

ERROR ErrorCounter : line 1:21: unexpected token: (
ERROR ErrorCounter : line 1:58: unexpected token: from
ERROR ErrorCounter : line 1:91: expecting "by", found '.'


I am confused... Can you please tell me whether
1. I cant use a SQL querry as such a parameter for createQuery().
2. Will hibernate mandatorily expect a table name next to the "from " keyword.
3. Can the above SQL scenerio represented in some way in HQL.


And any of your valuble inputs for me.

_________________
Celebrating Querying,
JagadeshK


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.