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: Using SQL In Clause with Hibernate
PostPosted: Fri Dec 29, 2006 1:22 am 
Newbie

Joined: Fri Dec 29, 2006 1:17 am
Posts: 3
Hi,

I need some help in Using SQL In Clause with Hibernate. How do I pass mutiple parameters in SQL IN clause using HQL and Criteria class?

Here's the example of the SQL.

select id, name, description from some_table where some_column in (?, ?, ?, ?, ?) order by id;

Best Regards,
Sanjay


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 29, 2006 6:10 am 
Regular
Regular

Joined: Wed Mar 23, 2005 8:43 am
Posts: 105
Location: Moscow, Russia
In HQL:

String queryString = "select id, name, description from Some s where s.someProperty in (:value1, :value2, :value3, :value4) order by s.id";

List results = session.createQuery(queryString)
.setParameter( "value1", value1, Hibernate.SOME_TYPE )
.setParameter( "value2", value2, Hibernate.SOME_TYPE)
.setParameter( "value3", value3, Hibernate.SOME_TYPE )
.setParameter( "value4", value4, Hibernate.SOME_TYPE)
.list();


In Criteria API:

What about Restrictions.in() ? For example:

Criterion somePropertyIn = Restrictions.in("some_property", new Object[] {"some_value1", "some_value2", "some_value3", "some_value4"});
Criteria crit = session.createCriteria(Some.class);
crit.add(somePropertyIn);
List results = crit.list();

_________________
Best Regards


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 05, 2007 2:49 am 
Newbie

Joined: Thu Mar 16, 2006 5:43 am
Posts: 5
Location: Delhi, India
Thanks for that piece of code, worked for me...

parmarsanjay should have posted a rating and should have given u the credit...

Thanks again

_________________
Thanks and Regards,
Cpt. Blue Streak
_______________________________________


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.