-->
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 question : entities in 'in'-clause
PostPosted: Mon Apr 19, 2010 5:07 am 
Beginner
Beginner

Joined: Wed Dec 10, 2008 5:59 am
Posts: 47
Hi,

I've just got a question regard HQL which i have been unable to find any answer to anywhere else.

Say i've got the following code:
Code:
Query q1 = sess.createQuery("from Track t where t.flag = :flag");
q1.setInteger("flag", 2);
List tracks = q1.list();

Query q2= sess.createQuery("from Track t left join fetch t.files where t in (:tracks);");
q2.setParameter("tracks", tracks);


I use setParameter("tracks", tracks) to use the tracks returned from the first query as a parameter in the
second query.

Now, should this work? Should Hibernate automatically know that it should use the id property of the Track entity
to compare items in the 'in'-clause? The alternative would be to use:

Code:
Query q1= sess.createQuery("select t.id from Track t where t.flag = :flag");
q1.setInteger("flag", 2);
List trackIds = q1.list();

Query q2 = sess.createQuery("from Track t left join fetch t.files where t.id in (:trackIds);");
q2.setParameter("trackIds", trackIds);


Love to hear any input on this one!


Top
 Profile  
 
 Post subject: Re: HQL question : entities in 'in'-clause
PostPosted: Mon Apr 19, 2010 5:46 am 
Beginner
Beginner

Joined: Wed Dec 10, 2008 5:59 am
Posts: 47
My bad...

I need to use setParameterList() instead of setParameter().


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.