title: Hibernate in Eclipse: java.lang.ArrayIndexOutOfBoundsException at oracle.jdbc.driver.OracleSql.main(OracleSql.java:1032)
body: <p>I am new to Hibernate. I am trying a sample application. The only output I get whenever I run either of <strong>DataStore.java</strong> or <strong>FetchData.java</strong> </p>
  
  <p>java.lang.ArrayIndexOutOfBoundsException: 0
      at oracle.jdbc.driver.OracleSql.main(OracleSql.java:1032)</p>
  
  <p>Am not able to find what causes this exception. The application is basic. Just creating two tables, one with Question ids and corresponding questions, another table with Answers with corresponding question ids as foreign key. This is my first try in hibernate. If any one can solve this problem, I will be indebted to them. Thanks in advance. </p>
  
  <p><strong>DataStore.java</strong>  </p>
  
  <pre><code>import java.util.ArrayList;
  import org.hibernate.Session;
  import org.hibernate.Transaction;
  import org.hibernate.cfg.Configuration;
  public class DataStore {
  public static void main(String[] args) {
      Session session = new Configuration().configure("hibernate.cfg.xml")
              .buildSessionFactory().openSession();
      Transaction t = session.beginTransaction();
  
      ArrayList&lt;String&gt; list1 = new ArrayList&lt;String&gt;();
      list1.add("java is a programming language");
      list1.add("java is a platform");
  
      ArrayList&lt;String&gt; list2 = new ArrayList&lt;String&gt;();
      list2.add("Servlet is an Interface");
      list2.add("Servlet is an API");
  
      Question question1 = new Question();
      question1.setQname("What is Java?");
      question1.setAnswers(list1);
  
      Question question2 = new Question();
      question2.setQname("What is Servlet?");
      question2.setAnswers(list2);
  
      session.persist(question1);
      session.persist(question2);
  
      t.commit();
      session.close();
      System.out.println("success");
  }
  }
  </code></pre>
  
  <p><strong>FetchData.java</strong></p>
  
  <pre><code>import java.util.Iterator;
  import java.util.List;
  import org.hibernate.Query;
  import org.hibernate.Session;
  import org.hibernate.cfg.Configuration;
  public class FetchData {
  public static void main(String[] args) {
  
      Session session = new Configuration().configure("hibernate.cfg.xml")
              .buildSessionFactory().openSession();
  
      Query query = session.createQuery("from Question");
      List&lt;Question&gt; list = query.list();
  
      Iterator&lt;Question&gt; itr = list.iterator();
      while (itr.hasNext()) {
          Question q = itr.next();
          System.out.println("Question Name: " + q.getQname());
  
          // printing answers
          List&lt;String&gt; list2 = q.getAnswers();
          Iterator&lt;String&gt; itr2 = list2.iterator();
          while (itr2.hasNext()) {
              System.out.println(itr2.next());
          }
  
      }
      session.close();
      System.out.println("success");
  }
  }
  </code></pre>
  
  <p><strong>question.hbm.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;class name="Question" table="Question"&gt;  
  &lt;id name="id" type="int" column="id"&gt;  
  &lt;generator class="increment"&gt;&lt;/generator&gt;  
  &lt;/id&gt;  
  &lt;property name="qname" column="qname" type="string"&gt;&lt;/property&gt;  
  &lt;list name="answers" table="Answers"&gt;  
  &lt;key column="id"&gt;&lt;/key&gt;  
  &lt;index column="type"&gt;&lt;/index&gt;  
  &lt;element column="answer" type="string"&gt;&lt;/element&gt;
  &lt;one-to-many class="Answer" /&gt;   
  &lt;/list&gt;  
  &lt;/class&gt;
  </code></pre>
  
  <p><strong>hibernate.cfg.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC"-//Hibernate/Hibernate Configuration DTD 3.0//EN"  
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;  
  &lt;hibernate-configuration&gt;  
  &lt;session-factory&gt;  
  &lt;property name="hbm2ddl.auto"&gt;update&lt;/property&gt;  
  &lt;property name="dialect"&gt;org.hibernate.dialect.Oracle10gDialect&lt;/property&gt;  
  &lt;property name="connection.url"&gt;jdbc:oracle:thin:@localhost:1521:xe&lt;/property&gt;  
  &lt;property name="connection.username"&gt;testuser&lt;/property&gt;  
  &lt;property name="connection.password"&gt;amudhan&lt;/property&gt;  
  &lt;property name="connection.driver_class"&gt;oracle.jdbc.driver.OracleDriver&lt;/property&gt;  
  &lt;mapping resource="question.hbm.xml"/&gt;  
  &lt;/session-factory&gt;  
  &lt;/hibernate-configuration&gt;  
  </code></pre>
  
  <p><strong>Question.java</strong></p>
  
  <pre><code>import java.util.List;
  public class Question {
  private int id;
  private String qname;
  private List&lt;String&gt; answers;
  
  /**
   * @return the id
   */
  public int getId() {
      return id;
  }
  
  /**
   * @param id
   *            the id to set
   */
  public void setId(int id) {
      this.id = id;
  }
  
  /**
   * @return the qname
   */
  public String getQname() {
      return qname;
  }
  
  /**
   * @param qname
   *            the qname to set
   */
  public void setQname(String qname) {
      this.qname = qname;
  }
  
  /**
   * @return the answers
   */
  public List&lt;String&gt; getAnswers() {
      return answers;
  }
  
  /**
   * @param answers
   *            the answers to set
   */
  public void setAnswers(List&lt;String&gt; answers) {
      this.answers = answers;
  }
  }
  </code></pre>
  
  <p><strong>Answer.java</strong></p>
  
  <pre><code>public class Answer {
  private int id;
  private String answer;
  private String posterName;
  
  /**
   * @return the id
   */
  public int getId() {
      return id;
  }
  
  /**
   * @param id
   *            the id to set
   */
  public void setId(int id) {
      this.id = id;
  }
  
  /**
   * @return the answer
   */
  public String getAnswer() {
      return answer;
  }
  
  /**
   * @param answer
   *            the answer to set
   */
  public void setAnswer(String answer) {
      this.answer = answer;
  }
  
  /**
   * @return the posterName
   */
  public String getPosterName() {
      return posterName;
  }
  
  /**
   * @param posterName
   *            the posterName to set
   */
  public void setPosterName(String posterName) {
      this.posterName = posterName;
  }
  }
  </code></pre>
  
  <p>Edit: This problem comes only when I add the following part in the <strong>question.hbm.xml</strong>. </p>
  
  <pre><code>&lt;list name="answers" table="Answers"&gt;  
  &lt;key column="id"&gt;&lt;/key&gt;  
  &lt;index column="type"&gt;&lt;/index&gt;  
  &lt;element column="answer" type="string"&gt;&lt;/element&gt;
  &lt;one-to-many class="Answer" /&gt;   
  </code></pre>
  
  <p>Simple insertion, updation with a single class/table work just fine. More than one class or table with foreign-key, the exception pops out.</p>