Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
HibernateTemplate query methods that support UserTypes [SPR-1159] #5861
Spring has no way of knowing what Hibernate Types to use in HibernateQueries, so if you attempt to use any of the find* methods in the template, and you are using a Hibernate UserType/CustomType(s) as query parameters, Spring/Hibernate will not be able to guess the type correctly.
It took me a while to figure out that you need to use a HibernateCallback to call the hibernate Query.setParamater(name, value, Type)
I would suggest adding some methods to the HibernateTemplate that support UserTypes, like..
findByNamedQuery(String queryName, Object value, org.hibernate.type.Type type)
findByNamedQuery(String queryName, Object values, org.hibernate.type.Type types)
Let me know if you would like me to submit a patch..
Juergen Hoeller commented
Well, I would actually recommend to implement a HibernateCallback for such cases. HibernateTemplate's should only cover typical cases, not necessarily all cases that an application might need. For such advanced parameter setting, the Hibernate Query API is probably nicer to use than any flattened HibernateTemplate convenience operation could be...
We actually have convenience operations on the HibernateTemplate for Hibernate 2.1. We've not ported those to the HibernateTemplate for Hibernate3 because there are quite a lot of new operations exposed there, and we wanted to keep the total number of convenience operations down. After all, an anonymous inner-class HibernateCallback is a pretty straightforward thing as well...