공통의 매핑정보가 필요할때 사용.
공통된놈이 객체마다 있으면 이것도 중복이다.
이것을 JPA에서 공통클래스를 만들어 관리할수 있다.
아래처럼 클래스 하나 만들어서 @MappedSuperClass를 해주면 된다.
물론 @Column을 사용해서 이름도 바꿀수있다.
그런다음 사용할 클래스에 extends를 쓰면됨.
근데 상속관계 매핑은 아니다!!
Entity가 아니다. 테이블도 만들지 않음.
MappedSuperClass는 조회 검색 불가함.
직접 생성해서 사용하는게 아니라 abstract 클래스로 만드는것 추천
@MappedSuperclass
public class BaseEntity {
@Column(name="Insert_Member")
private String createBy;
private LocalDateTime createDate;
private String lastModifiedBy;
private LocalDateTime lastModifiedDate;
public String getCreateBy() {
return createBy;
}
public void setCreateBy(String createBy) {
this.createBy = createBy;
}
public LocalDateTime getCreateDate() {
return createDate;
}
public void setCreateDate(LocalDateTime createDate) {
this.createDate = createDate;
}
public String getLastModifiedBy() {
return lastModifiedBy;
}
public void setLastModifiedBy(String lastModifiedBy) {
this.lastModifiedBy = lastModifiedBy;
}
public LocalDateTime getLastModifiedDate() {
return lastModifiedDate;
}
public void setLastModifiedDate(LocalDateTime lastModifiedDate) {
this.lastModifiedDate = lastModifiedDate;
}
}
'Developer' 카테고리의 다른 글
[JPA]지연로딩 - LAZY(관련 클래스는 프록시 객체로 가져옴) (0) | 2020.09.19 |
---|---|
[JPA]프록시객체 - getReference (와 find 차이) (0) | 2020.09.19 |
[JPA] 상속매핑(Inheritance) 전략 - TABLE_PER_CLASS (0) | 2020.09.19 |
[JPA] 상속매핑(Inheritance) 전략 - JOINED* (0) | 2020.09.19 |
[JPA] 상속매핑(Inheritance) 전략 - SINGLE_TABLE (0) | 2020.09.19 |