java.lang.ArrayIndexOutOfBoundsException: 2

Hibernate JIRA | Jose Vargas | 1 decade ago
  1. 0

    Using a windows XP professional PC, I am using the SchemaUpdate (<property name="hibernate.hbm2ddl.auto" value="update" />) to both update and create a database (Latest version of Derby) and I got a ArrayIndexOutOfBoundsException because there is an error in the following method: public boolean isTable(Object key) throws HibernateException { if(key instanceof String) { if ( getTableMetadata( (String) key, null, null ) != null ) { return true; } else { String[] strings = StringHelper.split(".", (String) key); if(strings.length==3) { return getTableMetadata(strings[2], strings[1], strings[2]) != null; } else if (strings.length==2) { return getTableMetadata(strings[2], strings[1], null) != null; } } } return false; } The indexes are wrong they should start from zero. strings[2],strings[1]. The correct implementation should be public boolean isTable(Object key) throws HibernateException { if(key instanceof String) { if ( getTableMetadata( (String) key, null, null ) != null ) { return true; } else { String[] strings = StringHelper.split(".", (String) key); if(strings.length==3) { return getTableMetadata(strings[1], strings[0], strings[2]) != null; } else if (strings.length==2) { return getTableMetadata(strings[1], strings[0], null) != null; } } } return false; } The stack trace is: 09:35:14,481 ERROR SchemaUpdate:167 - could not complete schema update java.lang.ArrayIndexOutOfBoundsException: 2 at org.hibernate.tool.hbm2ddl.DatabaseMetadata.isTable(DatabaseMetadata.java:147) at org.hibernate.cfg.Configuration.generateSchemaUpdateScript(Configuration.java:935) at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:144) at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:295) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1176) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:414) at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:575) at org.hibernate.ejb.Ejb3Configuration.createFactory(Ejb3Configuration.java:118) at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:165) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:103) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37) at com.motorola.nsm.common.cm.nodemanager.bl.NodeMgrBean.getInstance(NodeMgrBean.java:96) at com.motorola.nsm.common.cm.nodemanager.bl.NodeMgrBean.getNode(NodeMgrBean.java:186) at com.motorola.nsm.common.cm.nodemanager.bl.NodeMgrBean.print(NodeMgrBean.java:864) at com.motorola.nsm.common.cm.nodemanager.bl.CLIClient.main(CLIClient.java:12)

    Hibernate JIRA | 1 decade ago | Jose Vargas
    java.lang.ArrayIndexOutOfBoundsException: 2
  2. 0

    Using a windows XP professional PC, I am using the SchemaUpdate (<property name="hibernate.hbm2ddl.auto" value="update" />) to both update and create a database (Latest version of Derby) and I got a ArrayIndexOutOfBoundsException because there is an error in the following method: public boolean isTable(Object key) throws HibernateException { if(key instanceof String) { if ( getTableMetadata( (String) key, null, null ) != null ) { return true; } else { String[] strings = StringHelper.split(".", (String) key); if(strings.length==3) { return getTableMetadata(strings[2], strings[1], strings[2]) != null; } else if (strings.length==2) { return getTableMetadata(strings[2], strings[1], null) != null; } } } return false; } The indexes are wrong they should start from zero. strings[2],strings[1]. The correct implementation should be public boolean isTable(Object key) throws HibernateException { if(key instanceof String) { if ( getTableMetadata( (String) key, null, null ) != null ) { return true; } else { String[] strings = StringHelper.split(".", (String) key); if(strings.length==3) { return getTableMetadata(strings[1], strings[0], strings[2]) != null; } else if (strings.length==2) { return getTableMetadata(strings[1], strings[0], null) != null; } } } return false; } The stack trace is: 09:35:14,481 ERROR SchemaUpdate:167 - could not complete schema update java.lang.ArrayIndexOutOfBoundsException: 2 at org.hibernate.tool.hbm2ddl.DatabaseMetadata.isTable(DatabaseMetadata.java:147) at org.hibernate.cfg.Configuration.generateSchemaUpdateScript(Configuration.java:935) at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:144) at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:295) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1176) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:414) at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:575) at org.hibernate.ejb.Ejb3Configuration.createFactory(Ejb3Configuration.java:118) at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:165) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:103) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37) at com.motorola.nsm.common.cm.nodemanager.bl.NodeMgrBean.getInstance(NodeMgrBean.java:96) at com.motorola.nsm.common.cm.nodemanager.bl.NodeMgrBean.getNode(NodeMgrBean.java:186) at com.motorola.nsm.common.cm.nodemanager.bl.NodeMgrBean.print(NodeMgrBean.java:864) at com.motorola.nsm.common.cm.nodemanager.bl.CLIClient.main(CLIClient.java:12)

    Hibernate JIRA | 1 decade ago | Jose Vargas
    java.lang.ArrayIndexOutOfBoundsException: 2
  3. 0

    Hi, when i use the auto ddl feature (hibernate.hbm2ddl.auto = update) , hibernate throws an error like: 11:13:08,328 ERROR SchemaUpdate:167 - could not complete schema update java.lang.ArrayIndexOutOfBoundsException: 2 at org.hibernate.tool.hbm2ddl.DatabaseMetadata.isTable(DatabaseMetadata.java:147) at org.hibernate.cfg.Configuration.generateSchemaUpdateScript(Configuration.java:935) at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:144) at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:295) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1176) at com.db4o.replication.hibernate.MetaDataTablesCreator.createTables(MetaDataTablesCreator.java:60) at com.db4o.replication.hibernate.HibernateReplicationProviderImpl.<init>(HibernateReplicationProviderImpl.java:155) at com.db4o.replication.hibernate.HibernateReplicationProviderImpl.<init>(HibernateReplicationProviderImpl.java:137) at com.db4o.replication.Replication.wrap(Replication.java:104) at com.db4o.replication.Replication.begin(Replication.java:46) at com.db4o.replication.Replication.begin(Replication.java:57) at objectstore.ext.cache.CacheServer.main(CacheServer.java:103) I found something strange in the following class: package org.hibernate.tool.hbm2ddl; ........................... public class DatabaseMetadata { ............................. public boolean isTable(Object key) throws HibernateException { if(key instanceof String) { if ( getTableMetadata( (String) key, null, null ) != null ) { return true; } else { String[] strings = StringHelper.split(".", (String) key); if(strings.length==3) {<--- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! whats about index 0 !!!--> return getTableMetadata(strings[2], strings[1], strings[2]) != null; } else if (strings.length==2) { <---- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! whats about index 0 !!!--> return getTableMetadata(strings[2], strings[1], null) != null; } } } return false; } } Regards, Martin Kraus

    Hibernate JIRA | 1 decade ago | Martin Kraus
    java.lang.ArrayIndexOutOfBoundsException: 2
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Hi, when i use the auto ddl feature (hibernate.hbm2ddl.auto = update) , hibernate throws an error like: 11:13:08,328 ERROR SchemaUpdate:167 - could not complete schema update java.lang.ArrayIndexOutOfBoundsException: 2 at org.hibernate.tool.hbm2ddl.DatabaseMetadata.isTable(DatabaseMetadata.java:147) at org.hibernate.cfg.Configuration.generateSchemaUpdateScript(Configuration.java:935) at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:144) at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:295) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1176) at com.db4o.replication.hibernate.MetaDataTablesCreator.createTables(MetaDataTablesCreator.java:60) at com.db4o.replication.hibernate.HibernateReplicationProviderImpl.<init>(HibernateReplicationProviderImpl.java:155) at com.db4o.replication.hibernate.HibernateReplicationProviderImpl.<init>(HibernateReplicationProviderImpl.java:137) at com.db4o.replication.Replication.wrap(Replication.java:104) at com.db4o.replication.Replication.begin(Replication.java:46) at com.db4o.replication.Replication.begin(Replication.java:57) at objectstore.ext.cache.CacheServer.main(CacheServer.java:103) I found something strange in the following class: package org.hibernate.tool.hbm2ddl; ........................... public class DatabaseMetadata { ............................. public boolean isTable(Object key) throws HibernateException { if(key instanceof String) { if ( getTableMetadata( (String) key, null, null ) != null ) { return true; } else { String[] strings = StringHelper.split(".", (String) key); if(strings.length==3) {<--- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! whats about index 0 !!!--> return getTableMetadata(strings[2], strings[1], strings[2]) != null; } else if (strings.length==2) { <---- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! whats about index 0 !!!--> return getTableMetadata(strings[2], strings[1], null) != null; } } } return false; } } Regards, Martin Kraus

    Hibernate JIRA | 1 decade ago | Martin Kraus
    java.lang.ArrayIndexOutOfBoundsException: 2
  6. 0

    Error handling when reading from txt file

    Stack Overflow | 3 weeks ago | Buupu
    java.lang.ArrayIndexOutOfBoundsException: 2

    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.ArrayIndexOutOfBoundsException

      2

      at org.hibernate.tool.hbm2ddl.DatabaseMetadata.isTable()
    2. Hibernate
      SchemaUpdate.execute
      1. org.hibernate.tool.hbm2ddl.DatabaseMetadata.isTable(DatabaseMetadata.java:147)
      2. org.hibernate.cfg.Configuration.generateSchemaUpdateScript(Configuration.java:935)
      3. org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:144)
      3 frames
    3. Hibernate
      SessionFactoryImpl.<init>
      1. org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:295)
      1 frame
    4. Hibernate
      Configuration.buildSessionFactory
      1. org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1176)
      1 frame
    5. Hibernate EJB
      HibernatePersistence.createEntityManagerFactory
      1. org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:414)
      2. org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:575)
      3. org.hibernate.ejb.Ejb3Configuration.createFactory(Ejb3Configuration.java:118)
      4. org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:165)
      5. org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:103)
      5 frames
    6. JavaEE 7
      Persistence.createEntityManagerFactory
      1. javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37)
      1 frame
    7. com.motorola.nsm
      CLIClient.main
      1. com.motorola.nsm.common.cm.nodemanager.bl.NodeMgrBean.getInstance(NodeMgrBean.java:96)
      2. com.motorola.nsm.common.cm.nodemanager.bl.NodeMgrBean.getNode(NodeMgrBean.java:186)
      3. com.motorola.nsm.common.cm.nodemanager.bl.NodeMgrBean.print(NodeMgrBean.java:864)
      4. com.motorola.nsm.common.cm.nodemanager.bl.CLIClient.main(CLIClient.java:12)
      4 frames