users@glassfish.java.net

Re: How to Sort / OrderBy _at_OneToMany

From: <glassfish_at_javadesktop.org>
Date: Mon, 17 Sep 2007 13:56:43 PDT

That will get them in Id order. The value of the "@OrderBy" is presented in the persistence entity schema. Basically, this is the properties that you have defined in your entity class and not the actual names of the columns in the underlying database. So if you have some property line "name" and methods "getName" and 'setName", you could @OrderBy("name ASC") or @OrderBy("name DESC"). Ascending order is the default, so you do not need to specify it if you do not want to.

Before what I said that you must maintain the order in the list yourself, I was referring to the case where you are modifying the list in your code. So for example,
if you were doing something like:

    List<ObjectAttributes> list = yourEntity.getAttributes();
    ObjectAttributes newAttribute = ...
    list.add(x, newAttribute)

you need to make sure that you insert the newAttribute into the list in the correct position. When the list is retrieved from the persistent storage, the system will make sure the list is in the "@OrderBy" value, but after it is in working memory, your code is responsible for ensuring the ordering.
[Message sent by forum member 'bbergquist' (bbergquist)]

http://forums.java.net/jive/thread.jspa?messageID=235704