• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate - Enum

 
Craig Taylor
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm dealing with some model classes with some fields that have been declared as enum's. Allis well and happy in my little application world - _however_ we are not the sole users of the database and as such, other status's may appear in those enumerated fields.

Using @Enumerated(EnumType.STRING) with the proper enum type causes an exception. In a number of places we've had to change them to String fields and define final static values for comparison.

Thoughts / ideas on a solution that would allow my application to treat them as Enum's yet fail gracefully (eg: default value / skip record ... ) ?

Thanks,
 
Rodrigo Lopes
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you can use an approach simmilar to this to handle this situation.

You can make the nullSafeGet method to check if the enum value is defined.
[ July 24, 2008: Message edited by: Rodrigo Lopes ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic