-->
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: where myobject.id in ( myArrayList)
PostPosted: Thu Sep 23, 2004 11:31 am 
Newbie

Joined: Thu Sep 23, 2004 11:24 am
Posts: 2
Hibernate version: 2.1.6


Hi,

Is there anyway i can use existing java collections for the "in" clause ?

Say i have an arraylist "myArrayList" with Integers 1,3,5 and i want to return all myobjects with these id's

My query would become something like

from MyObject as myobject where myobject.id in ( myArrayList )


HQL is all about objects , so i figured this should be possible?
ATM i am just building a comma separated string like "1,3,5" and putting this in the query - it works but i figured there must be a nicer way.


Regards
Jorg


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 23, 2004 12:05 pm 
Beginner
Beginner

Joined: Mon Aug 16, 2004 6:15 am
Posts: 24
From the Hibernate 2.1.6 javadoc

setParameterList(String name, Collection vals)
Bind multiple values to a named query parameter, guessing the Hibernate type from the class of the first object in the collection.


so create your query with a bound parameter and use the above method to replace it.


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.