openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tedman Leung <ted...@sfu.ca>
Subject Re: how to store collection of enums as strings
Date Sun, 29 Mar 2009 04:27:01 GMT
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 <tedman@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
>>>                                                           tedman@sfu.ca
>>>
>>> It's time for a new bike when the bulb in your shift light burns out.
>>>
>>>     
>>
>>   
>

-- 
                                                           Ted Leung
                                                           tedman@sfu.ca

// /*
You know things are getting a little fishy when you're commenting out 
comments.
// */

Mime
View raw message