Let's say we have an enum with custom values, used as a persistent field in an entity:
public enum Sex { MALE(77), FEMALE(99); public int getValue() { return value; } int value; Sex(int v) { value = v; } }
Sex.MALE <=> 0 Sex.FEMALE <=> 1 // the default one, i.e. the var.ordinal() value
Sex.MALE <=> "MALE" Sex.FEMALE <=> "FEMALE" // using @Enumerated(STRING)
Sex.MALE <=> 77 Sex.FEMALE <=> 99 // i.e. the user-defined var.getValue() result
I ran into the same issue. I don't think there is a way to do what we want to do. The EJB specification doesn't seem to say anything about being able to use those custom values.
It probably has to be a vendor extension if it is supported at all.