-->
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: Abstract data types as parameters in named queries?
PostPosted: Thu Jan 12, 2006 6:55 pm 
Newbie

Joined: Thu Jan 12, 2006 6:29 pm
Posts: 2
Hibernate gurus,
Is it possible to pass an ADT, such as arrays, lists, or maps, as a parameter in a named query? In the documentation, in section 14.9, it would suggest that I can. Here is my named query definition, defined through an XDoclet tag:

Code:
/**
* @hibernate.query name="USERS_IN_LIST" query="from User u where u.username in elements ( :userNameList )"
*/

I call this query using the following (I'm using Spring to get the HibernateTemplate):

Code:
List target = getHibernateTemplate().findByNamedQueryAndValueBean("USERS_IN_LIST", criteria);

where the 'criteria' bean is an object which has a 'getUserNameList' method, and returns a string array (String[]). How do I pass this array into the query? When I tried this, it gives me an error that the query parser is looking for IDENT but found a ':', which would suggest that the 'elements' method cannot take a passed parameter. Is this true? The workaround is to dynamically generate a query by teasing out all the elements of the array and concatenating them into a query, but I want hibernate to handle the comparison. Any ideas?

Many thanks,

Mateja


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 12, 2006 9:44 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Yes. Use Query.setParameterList(), not Query.setParameter().


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 13, 2006 10:43 am 
Newbie

Joined: Thu Jan 12, 2006 6:29 pm
Posts: 2
Awesome! Thank you!

Mateja


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.