persistence@glassfish.java.net

Re: Maintaining an order of the list

From: Marina Vatkina <Marina.Vatkina_at_Sun.COM>
Date: Mon, 15 Oct 2007 20:01:12 -0700

Hi Aleksei,

Aleksei Valikov wrote:
> Hi.
>
>
>>The List in the JPA1.0 spec, even if annotated with @OrderBy, is not guaranteed
>>to be ordered at all times if the users in their code don't maintain the order
>>themselves:
>>
>>
>>>9.1.28 OrderBy Annotation
>>>
>>>The OrderBy annotation specifies the ordering of the elements of a collection
>>>valued association at the point when the association is *retrieved*.
>
>
> Thanks, I see.
>
>
>>I'm not sure if a Map can guarantee the order either :(.
>
>
> Well, yes. I was thinking of something like
>
>
> Map<Integer, T> resultMap = ...;
> for (int index = 0; index < list.size(); index++)
> {resultMap.put(index, list.get(index);}

Yeah, with the exception that in the spec your options for a non-pk index are
very limited too:

9.1.27 MapKey Annotation
...
If a persistent field or property other than the primary key is used as a map
key then it is expected to have a uniqueness constraint associated with it.

>
> in getter and the reverse think in setter.
>
> All in all, JPA 1.0 seems to be very limited. I'll direct my comments
> to the spec leads, I hope they care.

They are looking to really ordered lists.

Regards,
-marina

>
> Bye.
> /lexi