목차

JPA Composite Primary Key

@IdClass

@EmbeddedId

@AttributeOverrides

다른 엔티티들을 복합키로 가지기

@Entity
@Table(name = "EMP_PROJECT")
@IdClass(ProjectAssignmentId.class)
public class ProjectAssignment {
  @Id
  @Column(name = "EMP_ID", insertable = false, updatable = false)
  private int empId;
 
  @Id
  @Column(name = "PROJECT_ID", insertable = false, updatable = false)
  private int projectId;
 
  @ManyToOne
  @JoinColumn(name = "EMP_ID")
  Professor employee;
 
  @ManyToOne
  @JoinColumn(name = "PROJECT_ID")
  Project project;
  ..
}
 
public class ProjectAssignmentId implements Serializable {
  private int empId;
  private int projectId;
  ...
}

참조