Hibernate version:2.1.7
Hibernate Criteria.list() throws class cast exception when I feed search parameters to the Criteria object with Expression.in(). One of the search parameter( lata ) is defined as Integer in the persistent class(RcPK.java). The QueryParameters after adding user selected search parameters looks like this:
values[0] = [testmkt]
values[1] = [650]
types[0] = [hibernate.StringType]
types[1] = [hibernate.IntegerType]
But throws error on types[i].nullSafeSet(..)(protected int bindPositionalParameters(){}) in Loader.java. It's confusing why hibernate's type conversion is failing, and I donot want to converst search param to match with PersistentClass as it was supposed to be taken care by hibernate, isn't it?
Any feedback would be greatly appreciated.
my code snippet on popluating criteria object:
protected Criteria buildCriteria(Map criteriaMap) {
Criteria criteria = null;
String key = null;
Object[] values = null;
Iterator i = criteriaMap.keySet().iterator();
try {
criteria = getHibernateTemplate().createCriteria(getSession(), getPersistentClass());
while (i.hasNext()) {
key = (String) i.next();
values = (Object[]) criteriaMap.get(key);
//log.debug("Key = " + key + "Values = " + ((Object[]) criteriaMap.get(key)).length);
if (values.length > 0) {
criteria.add(Expression.in(key, values));
}
}
} catch (HibernateException he) {
throw convertHibernateAccessException(he);
}
return criteria;
}
Full stack trace of any exception that occurs:
java.lang.ClassCastException
at net.sf.hibernate.type.IntegerType.set(IntegerType.java:34)
at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:48)
at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:35)
at net.sf.hibernate.loader.Loader.bindPositionalParameters(Loader.java:749)
at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:788)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:265)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
at net.sf.hibernate.loader.CriteriaLoader.list(CriteriaLoader.java:118)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:3648)
at net.sf.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:238)
at com.level3.ssprov.mmae.persistence.dao.hibernate.HibernateObjectDao.criteriaSearch(HibernateObjectDao.java:72)
at com.level3.ssprov.mmae.persistence.dao.hibernate.HibernateObjectDao.search(HibernateObjectDao.java:44)
Name and version of the database you are using: Oracle 9.2.0.4
|