title: hibernate composite Primary key contains a composite foreign key, how to map this
body: <p>I searched there, and didn't find any similar topic, so I am posting a new question.</p>
  
  <p>I am working with Hibernate on an existing Database. The table structure and data we are not allowed to change. The application is reading data from the database and migrating to another datastore based on some logic.</p>
  
  <p>Now the problem is about a composite PK mapping. e.g.</p>
  
  <p>Table A has a composite PK.</p>
  
  <pre><code>Table A
  --------
  a1 (pk)
  a2 (pk)
  a3 (pk)
  a4 (pk)
  foo
  bar
  ========
  </code></pre>
  
  <p>Table B has a composite PK too, and one part of this composite PK is A's PK, here is working as FK as well. </p>
  
  <pre><code>Table B
  --------
  a1 (fk,pk)
  a2 (fk,pk)
  a3 (fk,pk)
  a4 (fk,pk)
  b1 (pk)
  b2 (pk)
  b3 (pk)
  foo
  bar
  ========
  </code></pre>
  
  <p>I tried several ways, and none of them works. Can anyone tell a working Hibernate mapping solution? better in annotation style.</p>