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