How To Preserve The Collection Order For The Target Of a Collection Mapping (Doc ID 971883.1)

Last updated on MAY 24, 2011

Applies to:

Oracle TopLink - Version: 11.1.1.0.1 and later   [Release: Oracle11g and later ]
Information in this document applies to any platform.

Goal


Collection Order Preservation (JPA 1.0)

Note:
The original document had been published on the EclipseLink homepage:
EclipseLink/Examples/JPA/Collectionordering

In some applications it is valuable to maintain collection ordering within the Java application. This requires that the order of a collection is maintained between writes and reads.

EclipseLink does provide support for ordering the target of a collection mapping (OneToMany, ManyToMany) but the order is not preserved in-memory and is not transparently saved. This example illustrates how an index column can be mapped in the target of a OneToMany mapping and used during the lifecycle of the entities to ensure the order set in the application is maintained when the collection is persisted and re-read.

Note:
Transparent support for order preservation will be provided in EclipseLink 2.0 as part of its JPA 2.0 implementation. This example is intended to help those using JPA 1.0 who need this functionality in EclipseLink 1.0 or 1.1.

Solution

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms