yes I know I can do manual hacks to get them stored the way I want to, but I was asking if there was a jpa / openjpa annotation to allow that.
As an example, I can just use @Enumerated on a single enum, so it seems logical that some one would have thought about storing a collection of enums. As for why I want them as strings instead of ordinals - the usual reasons, i.e. it's safer for changes as the ordering won't accidentally corrupt my data (and without telling me), and it's easier to look into the database via sql or something and just know what's going on / get simple reports etc. I'm guessing right now that it's not possible at all and that no one has done anything towards this. I might have to rummage through the source and try to see if I can figure out how it works and hack a patch to submit. It seemed like a very straight forward use case though so I'm surprised no one has asked or done anything about this before. On Sat, Mar 28, 2009 at 10:13:16PM -0700, Paul Copeland wrote: > What is your objective? Do you want some non-JPA application to see > them in the database as Strings? > > At some point you have add these Enums to the collection one at a time. > You can use an addEnum() method or an Entity listener to convert them to > Strings at that point one at a time. And a subclass of the Collection > type to getEnum() from the Collection when you fetch them back. > > new MyStringEnumHashSet<MyStringEnumType>() > > On 3/28/2009 9:27 PM, Tedman Leung wrote: >> No, I'm talking about when the enum is in a collection. >> >> i.e. >> >> Private HashSet<Gender> genders=new HashSet<Gender>(); >> >> So no, either the @Enumerated helps, nor does calling name() or >> toString as neither are possible. >> >> I'm storing a Collection of enums , not a single Enum. >> >> There seems to be no examples of this nor any documentation about the >> ability to do this that I can find. The default seems to use the >> ordinal value both for table generation and storage value. >> >> >> >> >> On Sat, Mar 28, 2009 at 01:56:13PM -0700, Paul Copeland wrote: >> >>> Hi - This is from the OpenJPA relations example - >>> >>> @Basic @Enumerated(EnumType.STRING) >>> private Gender gender; >>> >>> public static enum Gender { MALE, FEMALE } >>> >>> public void setGender(Gender gender) { >>> this.gender = gender; >>> } >>> >>> See section 12.8.1.2 in the OpenJPA Overview >>> >>> - Paul >>> >>> On 3/28/2009 1:33 PM, catalina wei wrote: >>> >>>> Ted, >>>> If you are using Java 5, then you could use name() or toString() API on the >>>> Enum to get the name of the enum constant in String value. >>>> >>>> Catalina >>>> >>>> On Wed, Mar 25, 2009 at 9:48 AM, Tedman Leung <ted...@sfu.ca> wrote: >>>> >>>> >>>>> Anyone know how to store a collection of enums as Strings instead of their >>>>> ordinal values? (preferably with annotations...) >>>>> >>>>> i.e. >>>>> @ManyToMany >>>>> private Set<MyEnum> myEnums=new HashSet<MyEnum>(); >>>>> >>>>> >>>>> -- >>>>> Ted Leung >>>>> ted...@sfu.ca >>>>> >>>>> It's time for a new bike when the bulb in your shift light burns out. >>>>> >>>>> >>>> >> >> > -- Ted Leung ted...@sfu.ca The most important words I've learned to say - "I don't know".