【问题标题】:How to map EnumSet (or List of Enums) in an entity using JPA2如何使用 JPA2 在实体中映射 EnumSet(或枚举列表)
【发布时间】:2011-02-05 16:04:48
【问题描述】:

我有实体人:

@Entity
@Table(schema="", name="PERSON")
public class Person {
    List<PaymentType> paymentTypesList;
    //some other fields     
    //getters and setters and other logic
}

我有枚举 PaymentType:

public enum PaymentType {
    FIXED, CO_FINANCED, DETERMINED;
}

如何持久化 Person 及其枚举列表(在此列表中,我必须放置可变数量的枚举,可能是其中一个,也可能是两个或全部)

我将 Spring 与 Postgres 一起使用,实体是使用 JPA 注释创建的,并使用 Hibernate 进行管理。

【问题讨论】:

    标签: mapping entity enumset


    【解决方案1】:

    问问自己,PaymentTypes 是否会随着时间而改变。

    我将创建一个具有一个名称属性的@Entity PaymentType,并在PaymentTypePerson 之间创建一个@Many2Many

    另一种方法:@ElementCollectionElementCollection from From Wikibooks, the open-content textbooks collection

    【讨论】:

      猜你喜欢
      • 2010-10-28
      • 2019-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-10
      • 1970-01-01
      • 2013-05-11
      • 1970-01-01
      相关资源
      最近更新 更多