@EmbeddedId : 식별자(PK, Key)로써 포함된다는 의미, 식별자 클래스는@Embeddable 어노테이션으로 다른 엔티티에 포함된다고 선언해야 하며 이 클래스는 @Id를 가질 수 없고 엔티티 객체와 같은 테이블에 저장된다. @Embeddable 어노테이션이 붙은 클래스의 멤버는 @AttributeOverride를 이용하여 칼럼 속성에 대한 재정의도 가능하다.
2. @EmbeddedId : 식별자(PK, Key)로써 포함된다는 의미, 식별자 클래스는
@Embeddable 어노테이션으로 다른 엔티티에 포함된다고 선언해야 하며 이 클
래스는 @Id를 가질 수 없고 엔티티 객체와 같은 테이블에 저장된다.
@Embeddable 어노테이션이 붙은 클래스의 멤버는 @AttributeOverride를 이
용하여 칼럼 속성에 대한 재정의도 가능하다.
2-2-2 식별자 매핑
(@EmbeddedId, @Embeddable)
탑크리에듀 http://www.topcredu.co.kr/
@Embeddable
public class UserPK implements Serializable {
String firstName;
String lastName;
3. 2-2-2 식별자 매핑
(@EmbeddedId, @Embeddable)
탑크리에듀 http://www.topcredu.co.kr/
public UserPK() { }
public boolean equals(Object other) {
if (other instanceof UserPK) {
final UserPK otherUserPK = (UserPK) other;
return (otherUserPK.firstName.equals(firstName) && otherUserPK.lastName.equals(lastName));
}
return false;
}
public int hashCode() { return super.hashCode(); }
}
@Entity
public class User {
public User() {}
@EmbeddedId
protected UserPK userPK;
}