-->
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.  [ 2 posts ] 
Author Message
 Post subject: HQL
PostPosted: Tue Sep 23, 2003 12:34 pm 
Newbie

Joined: Thu Sep 18, 2003 11:15 am
Posts: 6
I am trying to map the following query:

select c.col3
from table1 a, table2 c

where (a.col1_id = c.col2) and c.col3 in (select col3 from table2
where col2=51)

Below are my table defenitions
Table 1
col1 - PK

Table 2
col2- FK
col3

The above query works with Oracle. Can somebody suggest how to map it with HQL

thanks
BD


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 25, 2003 4:20 am 
Senior
Senior

Joined: Tue Sep 23, 2003 8:18 am
Posts: 137
Location: Johannesburg, South Africa
Try this:
Code:
Query q = session.createQuery("select c.col3 from table1 a, table2 c" +
" where a.col1 = c.col2 and c.col3 in (select d.col3 from table2 d where d.col2= :value)")";

q.setInteger("value", 51);

List listResult = q.list();


If that doesn't work, you can take the long route...two seperate queries...i.e. doing your inner query first, getting the list from it, and creating a StringBuffer of the elements. But, the above should work.
I added in the ":value", so that you can re-use the query for different col3 values. :)

Try reading through the HQL section of the Hibernate_Reference.pdf file, I go there often.

-G


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