1 Reply Latest reply on Dec 15, 2006 7:37 AM by Alex Grönholm

    @Enumerated with non-ordinal enumeration

    J Peschier Newbie

      Given this enumeration:

      public enum Gender {
      
       MALE ("M"), FEMALE ("F");
      
       private String codeInDatabase;
      
       private Gender(String codeInDatabase) {
       this.codeInDatabase = codeInDatabase;
       }
      
       public String getCodeInDatabase() {
       return codeInDatabase;
       }
      }

      and this fragment from my POJO:
       @Enumerated(EnumType.STRING)
       @Column(name = "gender")
       public Gender getGender() {
       return gender;
       }
       public void setGender(Gender gender) {
       this.gender = gender;
       }


      In the database the column "gender" contains the value M or F. When I query the pojo I get the following exception:
      javax.ejb.EJBException: java.lang.IllegalArgumentException:
      Unknown name value for enum class com.company.enumeration.Gender: M


      Is this a bug? Or is using non-ordinal enumerations not possible at all? I'm using 4.0.5.GA with the EJB3 profile.