title: Map ArrayList with Hibernate
body: <p>I just coded my first Hibernate examples.</p>
  
  <p>The database connection works and I understand how I can map a String from a POJO to a database field:</p>
  
  <pre><code>private String firstName;
  </code></pre>
  
  <p>And in the mapping file:</p>
  
  <pre><code>&lt;property name="firstName" type="java.lang.String"&gt;
      &lt;column name="FIRSTNAME" /&gt;
  &lt;/property&gt;
  </code></pre>
  
  <p>But how can I map an ArrayList to the database? A simpl example from the mapping xml file would be appreciated.</p>
  
  <p>Cheers</p>
  
  <p>UPDATE</p>
  
  <p>I switched to List instead of ArrayList found an example. Now I map as follows:</p>
  
  <pre><code>    &lt;list name="test" inverse="false" table="CONTACT" lazy="true"&gt;
          &lt;key&gt;
              &lt;column name="ID" /&gt;
          &lt;/key&gt;
          &lt;list-index&gt;&lt;/list-index&gt;
          &lt;element type="java.lang.String"&gt;
              &lt;column name="TEST" /&gt;
          &lt;/element&gt;
      &lt;/list&gt;
  </code></pre>
  
  <p>Unfortunately, I get an exception that I do not understand:</p>
  
  <pre><code>Exception in thread "main" org.hibernate.MappingException: Foreign key (FK6382B0003257FF7F:CONTACT [ID])) must have same number of columns as the referenced primary key (CONTACT [ID,idx])
  </code></pre>
  
  <p>Any ideas? </p>
  
  <p>Cheers</p>