[jboss-user] [EJB 3.0] - @Enumerated with non-ordinal enumeration

Jeilong do-not-reply at jboss.com
Wed Dec 13 06:38:57 EST 2006


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.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3993352#3993352

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3993352



More information about the jboss-user mailing list