java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer

Hibernate JIRA | Pawel Omelko | 6 years ago
  1. 0

    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?

    Hibernate JIRA | 6 years ago | Pawel Omelko
    java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
  2. 0

    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?

    Hibernate JIRA | 6 years ago | Pawel Omelko
    java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
  3. 0

    Patron searching - Funding date range search throws error

    GitHub | 6 years ago | StevensBrian
    java.lang.ClassCastException: java.util.Date cannot be cast to java.lang.String
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Patron search for patron publication date range throws error

    GitHub | 6 years ago | StevensBrian
    java.lang.ClassCastException: java.util.Date cannot be cast to java.lang.String
  6. 0

    Funding Date searching throws error

    GitHub | 6 years ago | StevensBrian
    java.lang.ClassCastException: java.util.Date cannot be cast to java.lang.String

  1. mortalman7 1 times, last 5 months ago
3 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. java.lang.ClassCastException

    java.lang.String cannot be cast to java.lang.Integer

    at org.hibernate.type.IntegerType.set()
  2. Hibernate
    CriteriaLoader.list
    1. org.hibernate.type.IntegerType.set(IntegerType.java:64)
    2. org.hibernate.type.NullableType.nullSafeSet(NullableType.java:154)
    3. org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
    4. org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1732)
    5. org.hibernate.loader.Loader.bindParameterValues(Loader.java:1703)
    6. org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1593)
    7. org.hibernate.loader.Loader.doQuery(Loader.java:696)
    8. org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
    9. org.hibernate.loader.Loader.doList(Loader.java:2232)
    10. org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129)
    11. org.hibernate.loader.Loader.list(Loader.java:2124)
    12. org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:118)
    12 frames
  3. Hibernate
    CriteriaImpl.list
    1. org.hibernate.impl.SessionImpl.list(SessionImpl.java:1597)
    2. org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306)
    2 frames