title: jpa one to many composite primary key mapping
body: <p>I have 2 tables as follows :</p>
  
  <pre><code>TABLE_A
  -------
  A_SIREN
  A_NDA
  
  TABLE_B
  -------
  B_id    
  B_NDA
  B_SIREN
  </code></pre>
  
  <p>The id of table A is a <code>COMPOSITE KEY</code> SIREN/NDA</p>
  
  <p>Here's the entities code.</p>
  
  <p>Key class</p>
  
  <pre><code>@Embeddable
  public class SirenNdaKey implements Serializable {
    @Column(name = "A_SIREN")        
    protected String siren;
    @Column(name = "A_NDA")        
    protected String nda;
    // getters setters
  }
  </code></pre>
  
  <p>TABLE A</p>
  
  <pre><code>public class EntityA{
  
     @EmbeddedId  
     private SirenNdaKey sirenNda;
  
     @OneToMany(fetch = FetchType.LAZY)
        @PrimaryKeyJoinColumns({ @PrimaryKeyJoinColumn(name = "A_SIREN", 
      referencedColumnName = "B_SIREN"),
        @PrimaryKeyJoinColumn(name = "A_NDA", referencedColumnName = "B_NDA") 
      })
     private Set&lt;EntityB&gt; EntityBSet;
     ...
  }
  </code></pre>
  
  <p>TABLE B</p>
  
  <pre><code>public class EntityB
      @Id
      private long id;
      @Column(name = "B_SIREN")
      private String siren;    
      @Column(name = "B_NDA")
      private String nda;
  }
  </code></pre>
  
  <p>Hibernate generate 3 tables : TABLE_A, TABLE_B and association table that contain A_NDA, A_SIREN, B_ID. How can I do to generate only 2 tables.</p>
  
  <p>My objectif is to find a list of entityB associated to the same couple SIREN/NDA from entity A (<code>entityA.getEntityBSet()</code>) without the need of the association table, because my tables are supplied by external batch.</p>
  
  <pre><code>entityA = entityARepository.findOne(new SirenNdaKey("nda_test1", "siren_test1"));
  entityA.getEntityBSet()  // this list is always empty
  </code></pre>