Return-Path: Delivered-To: apmail-openjpa-users-archive@locus.apache.org Received: (qmail 3194 invoked from network); 24 Mar 2008 19:28:48 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 24 Mar 2008 19:28:48 -0000 Received: (qmail 97787 invoked by uid 500); 24 Mar 2008 19:28:46 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 97776 invoked by uid 500); 24 Mar 2008 19:28:46 -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 97767 invoked by uid 99); 24 Mar 2008 19:28:46 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Mar 2008 12:28:46 -0700 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=SPF_PASS,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [206.190.38.42] (HELO web50201.mail.re2.yahoo.com) (206.190.38.42) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 24 Mar 2008 19:27:55 +0000 Received: (qmail 11458 invoked by uid 60001); 24 Mar 2008 19:28:14 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:Date:From:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=mVqiAQyAwlT2oOQfWpJNVN/PJIb6+1R4KJfGIJXHZaZKcBTFe826QJRwyyd/scjMX7t5chGNaDwmbBgZwdLIAaV+1XebUYE0C/tAqvxYb0NGrq5LJkbkGVI3W0sq81P1PEoEmqtt0b3IFl04PKF9bL9nymUH+IixuzCGn6KSPxM=; X-YMail-OSG: JGLuts8VM1mj9dS116OXsvpKV34YiLbSu94cv9NygUPX3nevgL1gvCQtRYo9jv8v5qSXz9qIwx0cVLiKVTPISJcr9PWTwTJx04BSlX.9.OyCp6ixQM1xFQ2_6HkjKYOceSgHPLtF0auvdYA- Received: from [149.32.224.34] by web50201.mail.re2.yahoo.com via HTTP; Mon, 24 Mar 2008 12:28:14 PDT Date: Mon, 24 Mar 2008 12:28:14 -0700 (PDT) From: os_developer Subject: Re: persist order in sorted collections To: users@openjpa.apache.org In-Reply-To: <47E7FF15.2010903@cs.cmu.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Message-ID: <891297.11381.qm@web50201.mail.re2.yahoo.com> X-Virus-Checked: Checked by ClamAV on apache.org Thanks Andy. I thought I may have read about it here before but was just having no luck finding it. I appreciate the links and info. Andrea --- Andy Schlaikjer wrote: > Here are two solutions, both of which involve the > @OrderBy annotation: > > http://openjpa.apache.org/docs/latest/manual/jpa_overview_meta_field.html#jpa_overview_meta_orderby > > (1) If your Entities themselves contain a column on > which you'd like to > sort, then use the @OrderBy annotation on the > collection field: > > @Entity > public class MyEntity > { > ... > @OneToMany() > @OrderBy("sortField") // > MySortableEntity.sortField > Collection sortedCollection; > ... > } > > (2) If your Entities do not (or cannot) contain an > extra field to > support sorting, then you can create a separate > Entity (a glorified join > table) to reference original entities and contain > sort info: > > @Entity > public class MyEntity > { > ... > @OneToMany() > @OrderBy("sortField") // > MySortableProxy.sortField > Collection sortedCollection; > ... > } > > @Entity > public class MySortableProxy > { > ... > @ManyToOne > protected MyUnsortableEntity entity; > > @Basic > protected long sortField; > ... > } > > I'd written to this list a while back about some > related issues: > > http://www.nabble.com/question-on-orderby-and-manytomany-td14822597.html > http://www.nabble.com/safe-to-%22reuse%22-table-for-mapping-of-separate-entities-relations--td15095287.html > > Cheers, > Andy > > > os_developer wrote: > > Hi, > > > > I wasn�t able to find a previous thread that > answers > > this although it does sound a bit familiar to > > me...feel free to refer me to a prior thread if > I�m > > repeating... > > > > My goal is to be able to be able to persist a > > Collection of data in a particular order (and > maintain > > that order when I retrieve it) and I�m hoping that > > someone may be able to tell me if I am going about > > this the correct way. For example, if I have a > list > > B-C-A, I want to persist it and then later > retrieve > > that list in the same order. The data itself > isn�t > > something I can just add an "order by" clause to > as > > the order is more time dependent. > > > > I�ve used an orm.xml and the ReverseMappingTool to > > generate my code, but even when I change the > default > > collection implementation to use an ordered or > sorted > > collection, I don�t get the expected results. > Perhaps > > I�m just implementing the collection usage wrong > or > > this is a feature not intended to be supported in > JPA? > > > > > > I�d rather not modify my database schema but so > far > > that�s where I feel like this is leading me. > > > > Any suggestions? > > > > Thanks, in advance, for any help you can offer. > > > > Andrea > > > > > > > > > ____________________________________________________________________________________ > > Be a better friend, newshound, and > > know-it-all with Yahoo! Mobile. Try it now. > http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ > > > ____________________________________________________________________________________ Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs