I want all enums in my classes persisted by JPA as Strings, not ordinal. Can I declare that globally someplace? I'm using Spring Data JPA + Hibernate + postgresql.
I want all enums in my classes persisted by JPA as Strings, not ordinal. Can I declare that globally someplace? I'm using Spring Data JPA + Hibernate + postgresql.
The answer is no.
Enum parameters are a compile time constants - there is no avenue to change them at runtime, and there's no way to craft a "project default".
Oddly, the only sane choice is STRING, mostly because ORDINAL is brittle; the order of your enums is forever locked in (data surgery notwithstanding), so I can't understand why the default is ORDINAL - I have never heard of any project using the it.