java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object;

Hibernate JIRA | Vyacheslav Dimitrov | 6 years ago
  1. 0

    We have byte[] field in one of our entity and we want to make query like this. {code} byte[] var = ...; Predicate p = builder.equal(root.get("ourByteField"), var); criteria.where(p); {code} But this code throws exception: [java] Exception in thread "main" java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object; [java] at org.hibernate.ejb.AbstractQueryImpl.registerParameterBinding(AbstractQueryImpl.java:349) [java] at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:364) [java] at org.hibernate.ejb.criteria.CriteriaQueryCompiler$1$1.bind(CriteriaQueryCompiler.java:194) [java] at org.hibernate.ejb.criteria.CriteriaQueryCompiler.compile(CriteriaQueryCompiler.java:247) [java] at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:441) [java] at ru.petrsu.nest.oqlite.test.TestParser.main(TestParser.java:92) [java] Java Result: 1 because class AbstractQueryImpl has code: {code} ... else if ( value.getClass().isArray() ) { final Object[] array = (Object[]) value; ... {code} We offer to change this "if" like this {code} ... else if ( value.getClass().isArray() && value.getClass().equals(Object[].class)) { final Object[] array = (Object[]) value; ... {code} Due to this new condition we get what we want and our criteria works fine. (At least ClassCastExceptio isn't occured). Patch is attached (Also I can do pull request, if needed).

    Hibernate JIRA | 6 years ago | Vyacheslav Dimitrov
    java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object;
  2. 0

    We have byte[] field in one of our entity and we want to make query like this. {code} byte[] var = ...; Predicate p = builder.equal(root.get("ourByteField"), var); criteria.where(p); {code} But this code throws exception: [java] Exception in thread "main" java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object; [java] at org.hibernate.ejb.AbstractQueryImpl.registerParameterBinding(AbstractQueryImpl.java:349) [java] at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:364) [java] at org.hibernate.ejb.criteria.CriteriaQueryCompiler$1$1.bind(CriteriaQueryCompiler.java:194) [java] at org.hibernate.ejb.criteria.CriteriaQueryCompiler.compile(CriteriaQueryCompiler.java:247) [java] at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:441) [java] at ru.petrsu.nest.oqlite.test.TestParser.main(TestParser.java:92) [java] Java Result: 1 because class AbstractQueryImpl has code: {code} ... else if ( value.getClass().isArray() ) { final Object[] array = (Object[]) value; ... {code} We offer to change this "if" like this {code} ... else if ( value.getClass().isArray() && value.getClass().equals(Object[].class)) { final Object[] array = (Object[]) value; ... {code} Due to this new condition we get what we want and our criteria works fine. (At least ClassCastExceptio isn't occured). Patch is attached (Also I can do pull request, if needed).

    Hibernate JIRA | 6 years ago | Vyacheslav Dimitrov
    java.lang.ClassCastException: [B cannot be cast to [Ljava.lang.Object;
  3. 0

    [HHH-6747] ClassCastException when rendering SimpleCaseExpression - Hibernate JIRA

    atlassian.net | 11 months ago
    java.lang.ClassCastException: java.lang.String cannot be cast to org.hibernate.ejb.criteria.Renderable
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

    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

      [B cannot be cast to [Ljava.lang.Object;

      at org.hibernate.ejb.AbstractQueryImpl.registerParameterBinding()
    2. Hibernate EJB
      AbstractEntityManagerImpl.createQuery
      1. org.hibernate.ejb.AbstractQueryImpl.registerParameterBinding(AbstractQueryImpl.java:349)
      2. org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:364)
      3. org.hibernate.ejb.criteria.CriteriaQueryCompiler$1$1.bind(CriteriaQueryCompiler.java:194)
      4. org.hibernate.ejb.criteria.CriteriaQueryCompiler.compile(CriteriaQueryCompiler.java:247)
      5. org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:441)
      5 frames
    3. ru.petrsu.nest
      TestParser.main
      1. ru.petrsu.nest.oqlite.test.TestParser.main(TestParser.java:92)
      1 frame