So in C++/C# you can create flags enums to hold multiple values, and storing a single meaningful integer in the database is, of course, trivial.
In Java you have Enu
Without going into the debate about pros and cons of ordinal values in the database - I posted a possible answer to the given question here: JPA map collection of Enums
The idea is to create a new PersistentEnumSet which uses the implementation of java.util.RegularEnumSet, but offers the elements bitmask to JPA.
That one can than be used in an embeddable:
@Embeddable
public class InterestsSet extends PersistentEnumSet {
public InterestsSet() {
super(InterestsEnum.class);
}
}
And that set is used in the entity:
@Entity
public class MyEntity {
// ...
@Embedded
private InterestsSet interests = new InterestsSet();
}
For further comments see my answer over there.