I'd like to see a simple way to persist an EnumSet (which if I understand this use case is really what is desired):

@Enumerated(STRING)
@ElementCollection
private EnumSet<MyEnum> myEnums = new EnumSet<MyEnum>();

If no volunteers to implement this one (too bad it's not in the specification) then this would be my second choice:

@Enumerated(STRING)
@ElementCollection
private Set<MyEnum> myEnums = new HashSet<MyEnum>();

The @Enumerated tells us that you want the String value of the enum to be persisted (not the int value); the @ElementCollection tells us to persist the values individually and not as a serialized blob.

Craig

On Mar 31, 2009, at 8:46 AM, Jody Grassel wrote:

It sounds like you're trying to persist a collection of enumerations as a
set of data and not as a reference to other entities, is that correct?

If so, wouldn't a combination of @PersistentCollection and Externalization
(section 6.6 in the manual) provide the function you are looking for?


On Wed, Mar 25, 2009 at 11: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.


Craig L Russell
Architect, Sun Java Enterprise System http://db.apache.org/jdo
408 276-5638 mailto:craig.russ...@sun.com
P.S. A good JDO? O, Gasp!

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to