-->
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.  [ 1 post ] 
Author Message
 Post subject: type conversion error: Criteria.list() for Expression.in()
PostPosted: Fri Apr 08, 2005 2:03 pm 
Newbie

Joined: Fri Apr 08, 2005 1:00 pm
Posts: 2
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.