====== JPA Composite Primary Key ====== * JPA 복합키 * [[http://stackoverflow.com/questions/212350/which-annotation-should-i-use-idclass-or-embeddedid|java - Which annotation should I use: @IdClass or @EmbeddedId]] - 둘 중에 ''@IdClass''가 더 사용하기 편하다는 얘기 ===== @IdClass ===== ===== @EmbeddedId ===== ===== @AttributeOverrides ===== ===== 다른 엔티티들을 복합키로 가지기 ===== * [[http://www.java2s.com/Code/Java/JPA/SetIdClassforCompoundKey.htm|Set IdClass for Compound Key : Primary Key]] @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; ... } ===== 참조 ===== * [[https://www.javacodegeeks.com/2019/04/identifiers-hibernate.html|Identifiers In Hibernate | Java Code Geeks - 2019]]