복합 값 타입 (Components)
@Embeddable
: 값 타입 정의@Embedded
: 값 타입 사용@AttributeOverrides
: 매핑 컬럼명이 중복인 경우@Embedded Address homeAddress;
@Embedded
@AttributeOverrides({
@AttributeOverride(name="city", column=@Column(name="COMPANY_CITY")),
@AttributeOverride(name="street", column=@Column(name="COMPANY_STREET")),
@AttributeOverride(name="zipcode", column=@Column(name="COMPANY_ZIPCODE"))
})
Address companyAddress;
==
equals()
@ElementCollection
@CollectionTable(name = "{table_name}", joinColumns = @JoinColumn(name = "{mapping_column_name}"))
// Collection 대체 entity
@Entity
public class AddressEntity {
@Id
@GeneratedValue
private Long id;
@Embedded Address address;
}
// Member entity
...
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "MEMBER_ID")
private List<AddressEntity> addressHistory = new ArrayList<AddressEntity>();
...