Spring/스프링 데이터 JPA
[스프링 데이터 JPA] JPA 프로그래밍 3. Value 타입 맵핑
주멘이
2021. 1. 10. 21:20
엔티티 타입과 Value 타입 구분
- 식별자가 있어야 하는가 (Account 도메인 클래스)
- 독립적으로 존재해야 하는가 (Address Composite Value 클래스)
Value 타입 종류
다른 타입에 종속적인 타입을 Value 타입이라고 보면 됨 (Address 클래스는 Account 도메인 클래스에 종속적이다.)
- 기본 타입 (String, Date, Boolean,...)
- Composite Value 타입
- Collection Value 타입
- 기본 타입의 컬렉션
- 컴포짓 타입의 컬렉션
Composite Value 타입 맵핑
- @Embadable: Composite Value 클래스에 지정하면 해당 클래스를 Composite Value로 만듦
- @Embadded: Entity에서 Composite Value로 지정한 클래스를 불러와 정의할 때 사용
- @AttributeOverrides: 여러 값을 오버 라이딩하기위한 그룹 어노테이션
- @AttributeOverride: 오버라이딩 하기 위해 사용
Address Composite Value 클래스
@Embeddable
public class Address {
private String street;
private String city;
private String state;
private String zipCode;
}
Account 도메인 클래스에서 Composite Value 클래스 로딩
@Embedded
@AttributeOverrides({
@AttributeOverride(name="street", column = @Column(name="home_street"))
})
private Address address;