Hello everyone,
I have been trying to store a Java enum in my database using JPA/EclipseLink. After looking through many options, none of which seems to be "perfect" I thought a small trick might work. I can create an enum with "two" representations: a short one to store in the DB and a descriptive one to use in my code. It would be something like this:
Then I can annotate my persistent fields like this:
so I can store "CR" in the DB, and write something like this in my Java code:
Is this a dumb idea? Will it explode a year from now? I think it covers many cases except the switch statement, where the compiler complains because Status.CREATED is not a constant (which I think it is).
Thanks for your suggestions!!
Juan M