title: How to map a HashMap with a List as a value in Hibernate
body: <p>As the subject says I want to map a HashMap with a List as a value in Hibernate.
  Since it looks like it is not possible to have a collection as element in a map in Hibernate, I have created a class that contains a list of Ids.</p>
  
  <p>My HashMap looks like this:</p>
  
  <pre><code>Map&lt;Status, IdList&gt; statusIdsMap = new HashMap&lt;Status, IdList&gt;();
  </code></pre>
  
  <p>Status is either insert/update/remove. IdList contains a List of Ids.</p>
  
  <p>Hibernate mapping looks like this:</p>
  
  <pre><code>&lt;id name="id" type="IdType" /&gt;
  ...
  &lt;map name="statusIdMap"&gt;
     &lt;key column="id" /&gt;
     &lt;map-key type="Status" column="StatusCode" /&gt;
     &lt;element type="IdList" /&gt;
  &lt;/map&gt;
  ...
  &lt;class name="IdList" select-before-update="true" table="IdList"&gt;
      &lt;id name="id" column="id" unsaved-value="null"&gt;
          &lt;generator class="IdGenerator"/&gt;
      &lt;/id&gt;
      &lt;set name="Ids" table="IdsForStatus"&gt;
          &lt;key column="id"/&gt;
          &lt;element column="updatedId" type="IdType"/&gt;
      &lt;/set&gt;
  &lt;/class&gt;
  </code></pre>
  
  <p>If I try to store the class with statusIdMap, Hibernate generates an Insert SQL that tries to put the IdList class in a column, instead of the Id to the IdList class.
  The Hibernate error message says "expected number, got binary".</p>
  
  <p>It's related question to this
  <a href="https://stackoverflow.com/questions/5266623/hibernatejpa-mapping-a-hashmap">Hibernate(JPA) mapping a HashMap</a>
  where the answer suggests to put list in the Key class, but it's not something I wish to do.</p>
  
  <p>Any other suggestions?</p>
  
  <p>EDIT:
  In short the test does following:</p>
  
  <p>Fills object with dummy values, including map.<br/>
  Initializing hibernate and starts a transaction<br/>
  Inserts object<br/>
  Commits transaction and closes hibernate session</p>
  
  <p>The error message comes from the database when trying to commit, since the generated insert statement is wrong as mentioned above.</p>