title: Ternary association with a composite primary key (JPA & Hibernate )
body: <p>I'm trying to make a ternary association with a composite primary key of 3 keys that reference 3 tables : REPORT, SCANNER and RISK , I have tried to implemente this using the code below, but I have a composite key with only 2 keys : riskId and reportId : </p>
  
  <p>Report.java</p>
  
  
  
  <pre><code>@Entity
  @Table(name="REPORT")
  public class Report {
      @Id
      @NotNull
      @GeneratedValue  
      private int reportId;
  
      @Column
      private String reportName;
  
      @OneToMany
      @MapKeyJoinColumn
      Map&lt;Risk, Scanner&gt; risks = new HashMap&lt;Risk, Scanner&gt;();
  }
  </code></pre>
  
  <p>Scanner.java :</p>
  
  <pre><code>@Entity
  @Table(name="SCANNER")
  public class Scanner{
      @Id
      @NotNull
      @GeneratedValue  
      private int scannerId;
  
      @Column
      private String scannerName; 
  }
  </code></pre>
  
  <p>Risk.java :</p>
  
  <pre><code>@Entity
  @Table(name="RISK")
  public class Risk {
      @Id
      @NotNull
      @GeneratedValue
      private int riskId;
  
      @Column
      private String issueName;
  }
  </code></pre>
  
  <p>So how to implemente a composite primary key with 3 keys ?</p>