title: Strange behaviour with composite-id and version in hibernate 3.6
body: <p>I encounter strange behaviour on Hibernate's <code>merge()</code> if I use an entity with a composite-id and a version number.</p>
  
  <p>This is my hibernate mapping file:</p>
  
  <pre><code>&lt;class name="ArticleTurnover" table="T_ARTICLETURNOVER"&gt;
      &lt;composite-id&gt;
          &lt;key-property name="mainArticleId" type="java.lang.Integer" column="ARTICLETURNOVER_ID"/&gt;
          &lt;key-property name="locationId" type="java.lang.Integer" column="ARTICLETURNOVER_LOCATIONID"/&gt;
      &lt;/composite-id&gt;
  
      &lt;version name="version" column="ARTICLETURNOVER_VERSION" /&gt;
      ... some properties
  &lt;/class&gt;
  </code></pre>
  
  <p>And this is the code (it fails...):</p>
  
  <pre><code>ArticleTurnover at = new ArticleTurnover();
  at.setMainArticleId(1);
  at.setLocationId(1);
  ArticleTurnover savedAt = em.merge(at);
  assertNotNull(savedAt.getMainArticleId());
  assertNotNull(savedAt.getLocationId());
  </code></pre>
  
  <p>After calling <code>merge</code> the fields mainArticleId and locationId are both <code>null</code>. The code above is just a test, but if I would commit a transaction, hibernate would insert null into the composite-id fields, and fail!</p>
  
  <p>If I change <code>em.merge(at)</code> to <code>em.persist(at)</code> everything works. And if I manually set <code>at.setVersion(0)</code> (!!) it also works.</p>
  
  <p>I ended up in adding a component type <code>ArticleTurnoverId</code> for my composite-id like mentioned here: <a href="http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/mapping.html#d0e4819" rel="nofollow">http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/mapping.html#d0e4819</a>.</p>
  
  <p>Can anybody tell me what I am doing wrong, or point out why this happens?</p>