-->
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: Setting named parameter in Query using "setParameterLis
PostPosted: Thu Oct 20, 2005 9:46 am 
Newbie

Joined: Thu Oct 28, 2004 1:58 am
Posts: 10
Location: Pune,India.
Option 1 :
StringBuilder idsAsString = new StringBuilder();
for(Long id: ids){
idsAsString.append(id);
idsAsString.append(",");
}
idsAsString.setLength(idsAsString.length() -1);
Query q = session.createQuery(String.format(
"select mf.id from AbstractMasterField mf where mf.id in (%s) and mf.id in (select bmf.baseMasterField.id from AbstractMasterField bmf where bmf.baseMasterField is not null)",
idsAsString.toString()));
return q.list();


Option 2:
Query q = session.createQuery("select mf.id from AbstractMasterField mf where mf.id in (:idList)");// and mf.id in (select bmf.baseMasterField.id from AbstractMasterField bmf where bmf.baseMasterField is not null)");
q.setParameterList("idList", ids, new LongType());
return q.list();

In given options, only (1) works. Option 2 doesn't work.
Both options are doing same thing.
Does anybody know why option 2 dont work?


Top
 Profile  
 
 Post subject: Re: Setting named parameter in Query using "setParamete
PostPosted: Thu Oct 20, 2005 9:50 am 
Newbie

Joined: Thu Oct 28, 2004 1:58 am
Posts: 10
Location: Pune,India.
Evenif, we dont speicify Type in "setParameterList", it doesnt work.
Also, ids is "List<Long>"


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.