@ElementCollection
- @Entity 가 아닌 기본 자바 클래스나 @Embeddable 클래스로 정의된 컬렉션을 다루며, OneToMany 의 관계를 갖는다.
@Entity
public class Sample extends AbstractAggregateRoot<Sample> {
@Id
@GeneratedValue
private Long SampleNo;
@ElementCollection
private Set<String> tags = new HashSet<String>();
@ElementCollection
@CollectionTable(name = "SampleScore",
joinColumns = @JoinColumn(name = "SampleNo"))
private List<SampleScore> scores = new ArrayList<SampleScore>();
}
@Embeddable
public class SampleScore {
@Column(nullable = false)
@Enumerated(EnumType.STRING)
private SampleItem item;
@Column(nullable = false)
private Integer score;
}
- 연관된 Entity 부모(Sample) 에 의해서만 관리되어진다.
- 항상 부모와 함께 저장되고 삭제 되므로 CASCADE 옵션은 제공되지 않는다.
- 부모 엔티티의 id 컬럼과 추가 컬럼으로 구성되어진다.