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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With