title: JPA Composite Key with Object references
body: <p>I have faced some issue while creating JPA Composite Key with Object references. Entities are as show in bellow,</p>
  
  <p>1) I wan to remove the <strong>ID</strong> field from Workflow entity and make a composite key with combining <strong>seqNo</strong> field and <strong>template</strong> (object reference) field</p>
  
  <p>2) According to that change updated the existing relationship with <strong>Command</strong> entity (@JoinColumn(name = "WORKFLOW_ID", referencedColumnName = "ID"))</p>
  
  <p>Thanks.</p>
  
  <p><strong>Template entity:</strong></p>
  
  <pre><code>@Entity
  @Table(name = "template")
  public class Template implements Serializable {
  
      @Id
      @GeneratedValue(strategy = GenerationType.SEQUENCE)
      @SequenceGenerator(name="template_se", sequenceName="TEMPLATE_SE", allocationSize=1, initialValue=1)
      @Basic(optional = false)
      @Column(name = "ID")
      private Integer id;
  
      @Basic(optional = false)
      @Column(name = "NAME", unique = true)
      private String name;
  
      @OneToMany(cascade = CascadeType.REMOVE, mappedBy = "template")
      @LazyCollection(LazyCollectionOption.FALSE)
      private List&lt;Workflow&gt; workflowList;
  }
  </code></pre>
  
  <p><strong>Workflow entity:</strong></p>
  
  <pre><code>@Entity
  @Table(name = "workflow")
  public class Workflow implements Serializable {
  
      @Id
      @GeneratedValue(strategy = GenerationType.SEQUENCE)
      @SequenceGenerator(name="wf_se", sequenceName="WF_SE", allocationSize=1, initialValue=1)
      @Basic(optional = false)
      @Column(name = "ID")
      private Integer id;
  
      @Basic(optional = false)
      @Column(name = "SEQ_NO")
      private int seqNo;
  
      @JoinColumn(name = "T_ID", referencedColumnName = "ID", nullable = false)
      @ManyToOne
      private Template template;
  
      @Basic(optional = false)
      @Column(name = "NAME")
      private String name;
  }
  </code></pre>
  
  <p><strong>Command entity:</strong></p>
  
  <pre><code>@Entity
  @Table(name = "command")
  public class Command implements Serializable {
  
      @Id
      @GeneratedValue(strategy = GenerationType.SEQUENCE)
      @SequenceGenerator(name="command_se", sequenceName="COMMAND_SE", allocationSize=1, initialValue=1)
      @Basic(optional = false)
      @Column(name = "ID")
      private Integer id;
  
      @JoinColumn(name = "WORKFLOW_ID", referencedColumnName = "ID")
      @ManyToOne(optional = false)
      private Workflow workflow;
  } 
  </code></pre>