开发者

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 PaymentTypes 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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜