In a project I java enums that are somewhat complex with multiple fields defining various business logic. I’m looking for a way to have these enums backed by a table/entity.
Optimally the enum could be an entity itself, but as far at I can tell the JPA spec does not allow for that. So question is if there is a way to somehow define an entity and map instances of one-to-one the the enum constants. Or is there a different way?
What I try to achieve is:
- Maintain full DDL with annotations (including foreign keys pointing to the enum table).
- Be able to create database views that join the entity table for more human readable representation (the system will save millions of records, so its important that the column that holds the enum reference can be as small as possible, probably a single byte).
I expect to write some application init code that ensures that the backing table is synced with the enum (if new constants were added).
Sorry I my question is a little vague, but I’m have trouble wording it, please let me know if you need clarifications.
Best regards Jens