How to map EnumSet (or List of Enums) in an entity using JPA2
I have entity Person:
@Entity
@Table(schema=""开发者_如何学编程, name="PERSON")
public class Person {
List<PaymentType> paymentTypesList;
//some other fields
//getters and setters and other logic
}
and I have enum PaymentType:
public enum PaymentType {
FIXED, CO_FINANCED, DETERMINED;
}
How to persist Person and its list of enums (in this list I have to place variable amount of enums, there may be one of them, or two or all of them)
I'm using Spring with Postgres, Entity are created using JPA annotation, and managed using Hibernate.
Ask yourself, wheter PaymentType
s can change over time.
I would create a @Entity PaymentType
with one name attribute, and create a @Many2Many
between PaymentType
and Person
.
Another approach: @ElementCollection
See ElementCollection from From Wikibooks, the open-content textbooks collection
精彩评论