[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Mapping @Enumerated to Numeric Values

jfrankman do-not-reply at jboss.com
Mon Jul 2 14:52:23 EDT 2007


All,

I have a column in a Table with values 1-9. Each value is a code that represents a certain value i.e.

1=Annual
2=Semi Annual
3=Quarterly

I want to map this column to an Enumeration. I have created the following Enumeration:



@Name("typePayment")
  | public enum TypePayment 
  | {
  | 1("Annual"),	
  | 2("SemiAnnual"),
  | 3("Quarterly")
  | }
  | 

In my class I have mapped a column to this enumeration as follows:


  | 	@Column(name = "TYPEPAYMENT")
  | 	@Enumerated(EnumType.STRING)
  | 	public TypePayment getTypePayment() {
  | 		return typePayment;
  | 	}
  | 

The problem is any value beginning with a number is not allowed as an enumerated value. So I get a compile error in my enumeration. I can change the enumeration to contain something like A, B, C instead of 1,2,3 but I am working against legacy data and cannot easily change the data values contained in the table from numbers to letters. 

So my question is, how can I map an enumeration to a table column where the values contained in the column will be digits 0-9?


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

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



More information about the jboss-user mailing list