-->
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: Hibernate equivalent to select * from my_tableID in('1','2')
PostPosted: Fri Oct 08, 2010 5:47 am 
Newbie

Joined: Tue May 11, 2010 6:38 pm
Posts: 5
Hi All,
I am trying to emulate the following query in Hibernate

Sql Query


Code:
select * from ORDER_HISTORY_SCR_VIEW where REFERENCE_ID in ('MOSU0002','MOSU0003')


Result:
Code:
ID                   Status 
=======      ====== 
MOSU0002       completed 
MOSU0003       completed 





But the issue is when i try this with Hibernate
HQl:
Code:
Criteria crr = session.createCriteria(MyTable.class); crr.add(Restrictions.in(columnPropertyName, errorOrdersFilterList)); System.out.println(crr.list());




Result
Code:
   ID                   Status 
   =======      ====== 
   MOSU0002       completed 
   MOSU0002       completed 




Issue: It fetches the same row twice .
Why is this anamoly ...................


Could any one post the solution


Top
 Profile  
 
 Post subject: Re: Hibernate equivalent to select * from my_tableID in('1','2')
PostPosted: Fri Oct 08, 2010 8:48 am 
Newbie

Joined: Wed Oct 06, 2010 12:49 pm
Posts: 8
I had to figure out how to use the "IN" clause the other day. The solution for me was to use the HibernateTemplate's findByNamedParam method.

So for your example, it would be something like this (where "OrderHistory" is the name of your entity class):

Code:
List<OrderHistory> orderHistoryResults = null;
HibernateTemplate ht = getHibernateTemplate();
String[] params = {"listParam"};
Object[] values = {"MOSU0002","MOSU0003"};
orderHistoryResults = ht.findByNamedParam("from OrderHistory h where h.referenceId in (:listParam)", params, values);


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.