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

jfrankman do-not-reply at jboss.com
Mon Jul 2 15:27:08 EDT 2007


I found a partial solution. If I do the following:

1.change the column from varchar to integer in the DB table.
2. Change the EnumType to ORDINAL
	@Column(name = "TYPEPAYMENT")
  | 	@Enumerated(EnumType.ORDINAL)
  | 	public TypePayment getTypePayment() {
  | 		return typePayment;
  | 	}

Then I can get it to work. This works except there is a gap in the values. Allowed values are 1-7 and 9. Zero and Eight are excluded. But since the ordinal begins with zero there is not a way for me to handle this unless I put a dummy enumerated values in positions 0 and 8 in my enumeration.


  | public enum TypePayment 
  | {
  | DUMMY0("dummy0"),
  | ANNUAL("Annual"),	
  | SEMI("Semi-Annual ($4 Fee)"),
  | FOUR_PAY("4-Pay ($12 Fee)"),
  | QUARTERLY("Quarterly ($12 Fee)"),
  | TWELVE_PAY("12-Pay (No Fee)"),
  | MONTHLY("Monthly"),
  | DEFERRED("Deferred ($7 Fee)"),
  | DUMMY8("dummy8"),
  | OTHER("Other")
  | ;
  | 

The problem with the above solution is that I will have to exclude ordinals 0 and 8 in my application by makeing them not appear in drop down boxes, etc.  I wish there was a way I could map and enumeration to numeric values using the EnumType(STRING).

Any ideas are appreciated.

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

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



More information about the jboss-user mailing list