Here is an example:
@Entity
public class EntityA {
@Id private int id;
@Enumerated( EnumType.ORDINAL )
private Measure measure;
public Measure getMeasure() {
return measure;
}
public void setMeasure(Measure measure) {
this.measure = measure;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
public enum Measure {
M1 ("M1", false),
M2 ("M2", false),
M3 ("M3", false),
M4 ("M4", false),
M5 ("M5", true);
private String description;
private Measure(String desc){
this.description=desc;
}
public String desc(){return this.description;}
}
--- On Wed, 9/17/08, Michael Vorburger <[EMAIL PROTECTED]> wrote:
> From: Michael Vorburger <[EMAIL PROTECTED]>
> Subject: Example of Enum mapping (fixed numbering)
> To: [email protected]
> Date: Wednesday, September 17, 2008, 8:29 AM
> Does anybody have a concrete example of how to map an enum
> with fixed
> ordinal numbering? I have a DB which has an numeric column
> where the
> existing values mean something. I want to map that to an
> Entity
> attribute of some enum type.
>
> Reading
> http://forums.oracle.com/forums/thread.jspa?threadID=658154
> and
> http://appfuse.org/display/APF/Java+5+Enums+Persistence+with+Hibernate
> I
> realize standard JPA does NOT actually do this (shame!
> hopefully this
> will be considered in JPA 2.0). However using some kind of
> Custom Field
> Mapping / Value Handler / Field Strategy annotation
> (http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_gui
> de_mapping_custom) this probably possible... any example
> handy?
>
> Thanks,
> Michael
>
>
> ____________________________________________________________
>
> • This email and any files transmitted with it are
> CONFIDENTIAL and intended
> solely for the use of the individual or entity to which
> they are addressed.
> • Any unauthorized copying, disclosure, or distribution
> of the material within
> this email is strictly forbidden.
> • Any views or opinions presented within this e-mail are
> solely those of the
> author and do not necessarily represent those of Odyssey
> Financial
> Technologies SA unless otherwise specifically stated.
> • An electronic message is not binding on its sender. Any
> message referring to
> a binding engagement must be confirmed in writing and
> duly signed.
> • If you have received this email in error, please notify
> the sender immediately
> and delete the original.