[hibernate-issues] [Hibernate-JIRA] Created: (HHH-5972) ClassCastException using SimpleExpression.ignoreCase on not VARCHAR property type
Pawel Omelko (JIRA)
noreply at atlassian.com
Wed Mar 2 07:45:08 EST 2011
ClassCastException using SimpleExpression.ignoreCase on not VARCHAR property type
---------------------------------------------------------------------------------
Key: HHH-5972
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5972
Project: Hibernate Core
Issue Type: New Feature
Components: query-criteria
Affects Versions: 3.6.1, 3.3.2
Environment: 3.3.2, postgresql 8.3
Reporter: Pawel Omelko
For given criteria:
hibernateTemplate.executeFind(new HibernateCallback() {
@Override
public Object doInHibernate(Session session) throws HibernateException, SQLException {
return session.createCriteria(Cat.class).add(Restrictions.eq("age", 7).ignoreCase()).list();
}
});
where "age" is Integer field of Cat.class, i have an exception:
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
at org.hibernate.type.IntegerType.set(IntegerType.java:64)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:154)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1732)
at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1703)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1593)
at org.hibernate.loader.Loader.doQuery(Loader.java:696)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.doList(Loader.java:2232)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129)
at org.hibernate.loader.Loader.list(Loader.java:2124)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:118)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1597)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)
I found somtthink like this in SimpleExpression.toSqlString(...) method
boolean lower = ignoreCase && ( sqlTypes[i]==Types.VARCHAR || sqlTypes[i]==Types.CHAR );
if (lower) {
//do something
}
I think that, same conditon should be added in method getTypedValues(...)
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery)
throws HibernateException {
//some needed code
boolean lower = ignoreCase && ( sqlTypes[i]==Types.VARCHAR || sqlTypes[i]==Types.CHAR );
Object icvalue = lower ? value.toString().toLowerCase() : value;
return new TypedValue[] { criteriaQuery.getTypedValue(criteria, propertyName, icvalue) };
}
but now, only ignoreCase condition is checked:
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery)
throws HibernateException {
Object icvalue = ignoreCase ? value.toString().toLowerCase() : value;
return new TypedValue[] { criteriaQuery.getTypedValue(criteria, propertyName, icvalue) };
}
Is any technical reason why sqlType in getTypedValues(...) method is not checked?
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list