How to persist an object that has an enumeration field?

The problem is the validator not the mapping! At org.hibernate.validator. NotEmptyValidator.

IsValid(NotEmptyValidator. Java:36) The Annotation @NotEmpty contains @Size(min = 1) and @Sizs supports only String, Collection, Map and Array.

1 So replace @NotEmpty by @NotNull – Ralph Nov 22 '10 at 16:36.

I think if you change @NotEmpty to @NotNull it should work. NotEmpty using a String should equate to: string! = null && string.trim().length() > 0 Using @Enumerated with String should persist Enum_WhifFunction.name() as the stored db value, so conversely it should do Enum_WhifFunction.

ValuOf(storedValue) to transfer the string value back to the enumeration. The problem likely occurs because the validator is likely attempting to do something like this: Object o = //get field String toValidate = (String) o; // throws a class cast if o is of type Enum_WhifFunction return toValidate! = null && toValidate.trim().length() > 0.

Java.lang. ClassCastException: nl.ru.cmbi.pdbeter.core.model.enums. Enum_WhifFunction cannot be cast to java.lang.

String at org.hibernate.validator. NotEmptyValidator. IsValid(NotEmptyValidator.

Java:36) @NotEmpty seems to be the source of the probelem not the @Enumerated annotation...

It might help to take a look at Mapping enum types with From the example there it looks like you should have: private Enum_WhifFunction whifFunction; @Enumerated(EnumType. STRING) public Enum_WhifFunction getWhifFunction() { return this. WhifFunction; }.

Still in my code it doesn't seem to be working. I'll try EnumType. ORDINAL when I get home to see if that might do the trick.

Still I'd like for the string representations of the enums to be in the database, and not numbers, in case a human is looking in the database directly. – FinalArt2005 Nov 22 '10 at 16:30.

Apparently Enum_WhifFunction cannot be cast to a String. Can you post the Enum_WhifFunction code?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions