views:

215

answers:

1

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

A: 

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

pihentagy

related questions