java.lang.ArrayIndexOutOfBoundsException: 2

Hibernate JIRA | Martin Kraus | 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

    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
  2. 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
  3. 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
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

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

    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. com.db4o.replication
      Replication.begin
      1. com.db4o.replication.hibernate.MetaDataTablesCreator.createTables(MetaDataTablesCreator.java:60)
      2. com.db4o.replication.hibernate.HibernateReplicationProviderImpl.<init>(HibernateReplicationProviderImpl.java:155)
      3. com.db4o.replication.hibernate.HibernateReplicationProviderImpl.<init>(HibernateReplicationProviderImpl.java:137)
      4. com.db4o.replication.Replication.wrap(Replication.java:104)
      5. com.db4o.replication.Replication.begin(Replication.java:46)
      6. com.db4o.replication.Replication.begin(Replication.java:57)
      6 frames
    6. objectstore.ext.cache
      CacheServer.main
      1. objectstore.ext.cache.CacheServer.main(CacheServer.java:103)
      1 frame