1 Reply Latest reply on Mar 10, 2006 9:55 AM by mazz

    Persisting enum fields with custom value mapping

    Atanas Todorov Newbie

      Let's say we have an enum with custom values, used as a persistent field in an entity:

      public enum Sex {
       public int getValue() {
       return value;
       int value;
       Sex(int v) {
       value = v;

      The spec defines two ways to map the enum property with the DB field:

      Sex.MALE <=> 0
       Sex.FEMALE <=> 1
       // the default one, i.e. the var.ordinal() value


      Sex.MALE <=> "MALE"
       Sex.FEMALE <=> "FEMALE"
       // using @Enumerated(STRING)

      That's ok, but is there an easy way to use some kind of custom mapping?

      In this case:

      Sex.MALE <=> 77
       Sex.FEMALE <=> 99
       // i.e. the user-defined var.getValue() result