Return-Path: Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: (qmail 93516 invoked from network); 29 Mar 2009 05:13:52 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 29 Mar 2009 05:13:52 -0000 Received: (qmail 99746 invoked by uid 500); 29 Mar 2009 05:13:51 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 99681 invoked by uid 500); 29 Mar 2009 05:13:51 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 99670 invoked by uid 99); 29 Mar 2009 05:13:51 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 29 Mar 2009 05:13:51 +0000 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [69.49.111.75] (HELO mail175c2.megamailservers.com) (69.49.111.75) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 29 Mar 2009 05:13:43 +0000 X-Authenticated-User: paul.copelandz.com Received: from [127.0.0.1] (ellen.pc.ashlandfiber.net [66.241.90.23] (may be forged)) (authenticated bits=0) by mail175c2.megamailservers.com (8.13.6/8.13.1) with ESMTP id n2T5DJ4N011021 for ; Sun, 29 Mar 2009 01:13:22 -0400 Message-ID: <49CF036C.7090001@jotobjects.com> Date: Sat, 28 Mar 2009 22:13:16 -0700 From: Paul Copeland Organization: JOT Object Technologies User-Agent: Thunderbird 2.0.0.5 (Windows/20070716) MIME-Version: 1.0 To: users@openjpa.apache.org Subject: Re: how to store collection of enums as strings References: <89c0c52c0903190744t56392cftac229b5c588d012@mail.gmail.com> <49C26A6D.6030901@jotobjects.com> <72c1350f0903200646k4c1bc792te22fa1ed0855e21d@mail.gmail.com> <72c1350f0903201325g802dfd1v2606b790be103c87@mail.gmail.com> <1237729192727-2516988.post@n2.nabble.com> <72c1350f0903231406n29257ddax5c42a74f7f7f4b77@mail.gmail.com> <1237992708968-2532837.post@n2.nabble.com> <20090325164829.GA20466@sfu.ca> <49CE8EED.6020509@jotobjects.com> <20090329042701.GA23209@sfu.ca> In-Reply-To: <20090329042701.GA23209@sfu.ca> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org 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() 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 genders=new HashSet(); > > 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 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 myEnums=new HashSet(); >>>> >>>> >>>> -- >>>> Ted Leung >>>> tedman@sfu.ca >>>> >>>> It's time for a new bike when the bulb in your shift light burns out. >>>> >>>> >>>> >>> >>> > >