Let's assume I do have an Offer
entity. It has a property salaries
that may be a list of Salary
objects. The Salary
cannot exist without an Offer
, so does it mean I should use @ElementCollection
or may not? When should we use @ElementCollection
and when @OneToMany
. The same question comes to my mind when we talk about @Embeddable
and @Embedded
, is it worth using it, or perhaps it's better to have a @OneToOne
relationship.
class Salary(
val salary_from: Integer,
val salary_to: Integer,
val salary_type: Type
)
class Offer(
@ElementCollection
@CollectionTable(name = "offer_salaries", joinColumns = @JoinColumn(name = "offer_id"))
@OrderColumn
@Column(name = "salaries")
val salaries: List<Salary>;
)