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.  [ 5 posts ] 
Author Message
 Post subject: Can JDBC IN parameters use with Array String or List?
PostPosted: Sun Jan 22, 2006 12:56 pm 
Regular
Regular

Joined: Mon Aug 02, 2004 9:33 am
Posts: 69
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.1

Mapping documents:
<query name="PostingListByCategoryId"><![CDATA[
from CategorizedItem ci where ci.id.categoryId in (?)
]]></query>


Name and version of the database you are using:Mysql 5.0

Hi guys,

I got a list of Long value store inside an array or a List. How could this possibly pass into the IN parameter ? I got error mesasge like follow:


[junit] [stufftolet] WARN [main] JDBCExceptionReporter.logExceptions(71) | SQL Error: 0, SQLState: S1009
[junit] [stufftolet] ERROR [main] JDBCExceptionReporter.logExceptions(72) | Statement parameter 1 not set.


pls help ,thanks !

regards,
Mark


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 22, 2006 1:05 pm 
Regular
Regular

Joined: Mon Aug 02, 2004 9:33 am
Posts: 69
my query code is something like below:

public List findPostingList(List allChild) {
return getHibernateTemplate().findByNamedQuery(
"PostingListByCategoryId", allChild);
}


pls help, Thanks !


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 22, 2006 1:45 pm 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
Change your namedquery like
Code:
<query name="PostingListByCategoryId"><![CDATA[
from CategorizedItem ci where ci.id.categoryId in (:cids)
]]></query>


and the calling code as
Code:
List l  = new ArrayList();
//Populate the List
session.getNamedQuery("PostingListByCategoryId").setParameterList("list", l);


But thats purely using Hibernate.
As far as Spring is concerned, I can see an API like
getHibernateTemplate().findByNamedQuery(namedquery, Object value);
Maybe you can create your list and pass it as the value ?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 22, 2006 1:54 pm 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
If you are going to use just hibernate, then the first approach mentioned in my previous comment would work, But if you need to use spring, use the named query like
Code:
<query name="PostingListByCategoryId"><![CDATA[
from CategorizedItem ci where ci.id.categoryId in (:cids)
]]></query>


and use the Spring method
findByNamedQueryAndNamedParam as
Code:
List l = new ArrayList();
//pass values to ArrayList
getHibernateTemplate().findByNamedQueryAndNamedParam("PostingListByCategoryId", "cids", l);


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 22, 2006 10:37 pm 
Regular
Regular

Joined: Mon Aug 02, 2004 9:33 am
Posts: 69
hey man, Thanks a lot !


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.