I am trying to write a generic method that can pick up a named query, set the named parameters in it and return a result.
The method looks like the following,
s = getSession();
q = s.getNamedQuery(nameOfTheQuery);
keySet = queryParams.keySet();
itr = keySet.iterator();
while(itr.hasNext()){
key = itr.next();
//Problem here
q.setParameter(key, queryParams.get(key));
}
q.setMaxResults(maxResults);
q.setFetchSize(fetchSize);
log.info("::>>>> Query result :"+(q.uniqueResult()));
I am trying to set the named parameters to values here. But when the parameter here happens to be a list or collection I get a ClassCastException while the q.uniqueResult()
Is there a way I can write this method to support collections and other types of parameters as well? It is mandatory that I set the maxResults and fetchSize so I had to choose this option. Any help would be greatly appreciated. Thanks!