Hi,
  The simple way to do this is via @ExternalValues. Unfortunately,
@ExternalValues did not support enum types. With latest commit on trunk
revision 893504 [1], that support has been added.

  Here is an example of enum valued field stored as numbers in database.

public class Movie {
    public enum Rating {GOOD, BAD, UGLY};
    
    @Id
    private String title;
    
   /** need not be contiguous.
     *  Specify as key=value pairs where key is the Enum and value is the
integer in the database
     *  @Type denotes the type stored in database
    */ 
    @ExternalValues({"GOOD=5", "BAD=2", "UGLY=1"})
    @Type(int.class)
    private Rating rating;

   Query parameter will work as enum:
       em.createQuery("select m from Movie m where m.rating=:rating")
           .setParameter("rating", Movie.Rating.GOOD)
           .getResultList();
    

[1] http://issues.apache.org/jira/browse/OPENJPA-1445



KARR, DAVID (ATTCINW) wrote:
> 
> I'm trying to map a field that is essentially an enumerated type.  The
> ordinal values are stored in the DB.  I can specify
> "@Enumerated(EnumType.ORDINAL)" on the field, and then in the definition
> of my Java enumerated type, I can define the possible values I can
> expect.  What seems to be missing here is that I have to map specific
> ordinal values.  I can't just assume the first value maps to "0", and so
> on.  I don't see an obvious way to define an enumerated type where I can
> set the ordinal values.  Am I missing something simple here?
> 
> 


-----
Pinaki 
-- 
View this message in context: 
http://n2.nabble.com/How-to-get-hardcoded-ordinal-values-to-map-to-specific-Enum-values-tp4183005p4208794.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to