Using @Enumerated for Enum persistence, I get a String representation or an Integer in my database. Nothing prevents me from changing those values directly in the database. However, when my object is loaded I'll get an Exception.
Is there a way to make validation in the DB itself to prevent that value from being changed? Something like persisting my enum type as an entity and forbid this table from being updated? Or setting a restriction in the database (through annotations) so that some field can only accept certain values?
Some ideas:
- To implement a UserType in hibernate so that I can make a custom mapping
- To clone my enum into a Class and then do some code hacking so that the enum can be accepted instead of my class
Any suggestions?
Thanks
|