I am using MySQL database with Hibernate and there are certain Enum fields that allow NULL or empty values. It is all fine until a query is made and Hibernate tries to map the empty value on the Enum defined. I am unable to define a value in Enum that would work, because Enum does allow white-spaces.
Enum class:
private enum ObjType {
itemA,
itemB,
NULL
}
It takes NULL as a member but that does not help. I am new to EE Java, and would appreciate any help.
Thanks
you can add a
unknownordefaultorinvalidvalue to your enum which will be mapped in case if it isnullorempty spaceUsing
fromValuemethod you can get enum object from value.using
toStringmethod you can get value of an enum object.mapwill contain value to enum object mapping. If the value likenullorempty spacedoes not exist in map, the map will return null and in that case the methodfromValuewill returnUNKNOWNenum object.