java.lang.ArrayIndexOutOfBoundsException: 1

Hibernate JIRA | jerome bonnet | 1 decade ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    I am triggered an ArrayIndexOutOfBound Exception in the hibernate code. This happens when I try to bind a positional parameter of type object. For instance: List finds = session.find("from package.MyClass as myclass where myclass.myAttrib=?", subobject, Hibernate.OBJECT); where myclass.myAttrib is a many-to-one relationship to subobject. The stacktrace is: java.lang.ArrayIndexOutOfBoundsException: 1 at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:2005) at com.mysql.jdbc.PreparedStatement.setBytes(PreparedStatement.java:493) at net.sf.hibernate.type.BinaryType.set(BinaryType.java:28) at net.sf.hibernate.type.SerializableType.set(SerializableType.java:28) at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:48) at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:35) at net.sf.hibernate.type.ObjectType.nullSafeSet(ObjectType.java:144) at net.sf.hibernate.loader.Loader.bindPositionalParameters(Loader.java:674) at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:713) at net.sf.hibernate.loader.Loader.doQuery(Loader.java:185) at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133) at net.sf.hibernate.loader.Loader.doList(Loader.java:950) at net.sf.hibernate.loader.Loader.list(Loader.java:941) at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:834) at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1512) at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1491) at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1487) Using a debugger I have found that the index is 2 instead of 1 in PreparedStatement.setByte Of course this cannot work and should come from hibernate mapping. Debugging a little further I have found that in ObjectType.nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) I think that there is an error: metaType.nullSafeSet(st, clazz, index, session); identifierType.nullSafeSet(st, id, index+1, session); // metaType must be single-column type ^^^^^^^^^^^^^ ^^^^^^ The index+1 is wrong it should be index. I am not sure but I think the other types does not have such +1...

    Hibernate JIRA | 1 decade ago | jerome bonnet
    java.lang.ArrayIndexOutOfBoundsException: 1
  2. 0

    I am triggered an ArrayIndexOutOfBound Exception in the hibernate code. This happens when I try to bind a positional parameter of type object. For instance: List finds = session.find("from package.MyClass as myclass where myclass.myAttrib=?", subobject, Hibernate.OBJECT); where myclass.myAttrib is a many-to-one relationship to subobject. The stacktrace is: java.lang.ArrayIndexOutOfBoundsException: 1 at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:2005) at com.mysql.jdbc.PreparedStatement.setBytes(PreparedStatement.java:493) at net.sf.hibernate.type.BinaryType.set(BinaryType.java:28) at net.sf.hibernate.type.SerializableType.set(SerializableType.java:28) at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:48) at net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:35) at net.sf.hibernate.type.ObjectType.nullSafeSet(ObjectType.java:144) at net.sf.hibernate.loader.Loader.bindPositionalParameters(Loader.java:674) at net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:713) at net.sf.hibernate.loader.Loader.doQuery(Loader.java:185) at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133) at net.sf.hibernate.loader.Loader.doList(Loader.java:950) at net.sf.hibernate.loader.Loader.list(Loader.java:941) at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:834) at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1512) at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1491) at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1487) Using a debugger I have found that the index is 2 instead of 1 in PreparedStatement.setByte Of course this cannot work and should come from hibernate mapping. Debugging a little further I have found that in ObjectType.nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) I think that there is an error: metaType.nullSafeSet(st, clazz, index, session); identifierType.nullSafeSet(st, id, index+1, session); // metaType must be single-column type ^^^^^^^^^^^^^ ^^^^^^ The index+1 is wrong it should be index. I am not sure but I think the other types does not have such +1...

    Hibernate JIRA | 1 decade ago | jerome bonnet
    java.lang.ArrayIndexOutOfBoundsException: 1

    Root Cause Analysis

    1. java.lang.ArrayIndexOutOfBoundsException

      1

      at com.mysql.jdbc.PreparedStatement.setInternal()
    2. MySQL jdbc
      PreparedStatement.setBytes
      1. com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:2005)
      2. com.mysql.jdbc.PreparedStatement.setBytes(PreparedStatement.java:493)
      2 frames
    3. net.sf.hibernate
      SessionImpl.find
      1. net.sf.hibernate.type.BinaryType.set(BinaryType.java:28)
      2. net.sf.hibernate.type.SerializableType.set(SerializableType.java:28)
      3. net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:48)
      4. net.sf.hibernate.type.NullableType.nullSafeSet(NullableType.java:35)
      5. net.sf.hibernate.type.ObjectType.nullSafeSet(ObjectType.java:144)
      6. net.sf.hibernate.loader.Loader.bindPositionalParameters(Loader.java:674)
      7. net.sf.hibernate.loader.Loader.prepareQueryStatement(Loader.java:713)
      8. net.sf.hibernate.loader.Loader.doQuery(Loader.java:185)
      9. net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
      10. net.sf.hibernate.loader.Loader.doList(Loader.java:950)
      11. net.sf.hibernate.loader.Loader.list(Loader.java:941)
      12. net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:834)
      13. net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1512)
      14. net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1491)
      15. net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1487)
      15 frames