Ways to save enums in database
- by corgrath
Hey guys.
I am wondering what the best ways to save enums into a database is.
I know there are name() and valueOf() methods to make it into a String back. But are there any other (flexible) options to store these values?
Is there a smart way to make them into unique numbers (ordinal() is not safe to use)?
Any comments and suggestions would be helpful :)
Update:
Thanks for all awesome and fast answers! It was as I suspected.
However a note to 'toolkit'; That is one way. The problem is that I would have to add the same methods with each enum type i create. Thats a lot of duplicated code and, at the moment, Java does not support any solutions to this (You cannot let enum extend other classes).
However, thanks for all answers!