openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Vorburger" <mvorbur...@odyssey-group.com>
Subject RE: Example of Enum mapping (fixed numbering)
Date Wed, 17 Sep 2008 18:55:32 GMT
> I'll try to extend that example to play with Custom Field Mapping /
Value Handler / Field Strategy stuff, and if I can get it to work, post
an example somewhere.

Got it working! - It's more than a few lines, I'll upload / describe it
somewhere when I get a chance, and post a link here.


-----Original Message-----
From: Michael Vorburger [mailto:mvorburger@odyssey-group.com] 
Sent: mercredi, 17. septembre 2008 19:07
To: users@openjpa.apache.org; fyw300@yahoo.com
Subject: RE: Example of Enum mapping (fixed numbering)

I got an example like yours below working, but this would store M1 as 0
and M2 as 1 etc. won't it?  I wanted to say store M1 as... 4, and M2
as... 7 and M5 as 9873.

I'll try to extend that example to play with Custom Field Mapping /
Value Handler / Field Strategy stuff, and if I can get it to work, post
an example somewhere.

PS: Also, I initially had <class>SomeEnum</class> listed in
persistence.xml, and that leads to confusing errors "Type class SomeEnum
does not have persistence metadata." or "This configuration disallows
runtime optimization, but the following listed types were not enhanced
at build time or at class load time with a javaagent: "[class
...SomeEnum]".


-----Original Message-----
From: Fay Wang [mailto:fyw300@yahoo.com]
Sent: mercredi, 17. septembre 2008 17:51
To: users@openjpa.apache.org
Subject: Re: Example of Enum mapping (fixed numbering)

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 <mvorburger@odyssey-group.com>
wrote:

> From: Michael Vorburger <mvorburger@odyssey-group.com>
> Subject: Example of Enum mapping (fixed numbering)
> To: users@openjpa.apache.org
> 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_g
> ui
> 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.


      

____________________________________________________________

* 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.

____________________________________________________________

 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.

Mime
View raw message