openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matthew Adams <>
Subject OpenJPA 1.2.x & map key as enum stored as string (probably a FAQ)
Date Wed, 14 Apr 2010 16:59:36 GMT
Hi all,

Sorry if this is a FAQ.  I can't seem to find it in the docs or googling.

I have the following scenario and just need to know which
OpenJPA-specific annotations to apply to my field.  The scenario is a
field of type Map where the map key is an enum that I want to store as
@Enumerated(EnumType.STRING) and is not an attribute of the values in
the map using OpenJPA 1.2.x & JPA 1.0 (can't go to JPA 2.0 yet).
Assume all classes use a simple @Id field of type Long.

public enum Place { HOUSE, CAVE, LEAN_TO, BARE_SPOT; }

public class WildThing {
  /* NOTE: does **not** have a field of type Place! */
  protected Long id;
  protected String name;

public class WhereTheWildThingsAre {

  protected Long id;

  // what annotation(s) do I put here?
  @OneToMany(cascade =
    { CascadeType.MERGE, CascadeType.REFRESH, CascadeType.PERSIST })
  protected Map<Place,WildThing> thingsByClassification
    = new HashMap<Place,WildThing>;


Again, I want the key to be stored as the string representation of the
enum constant.



View raw message