Suppose I have a dictionary (i.e. gender: MALE, FEMALE) used in my application.
I'd wish to use this dictionary as a Java enum
. Moreover, this dictionary values are referenced from a bunch of other tables, so you'd wish to have it a separate table.
The Java enum
cannot be an entity itself. I can use the enum
attribute (annotated as @Enumerated
) in my Entity classes but this will save the enumeration (as an Integer, char or String) in every table that use this enum
instead of using a FK to the dictionary table.
How would you implement such use case?
- Create a Dictionary
entity with static method producing enum
values?
- Modified getter and setter for Dictionary
which returns an enum
instead of Dictionary
instance?
- ...or perhaps you've never needed to persist an enum
in a separate table?