Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/Examples/JPA/Collectionordering"

m (Maintain Collection Ordering)
(Maintain Collection Ordering)
Line 1: Line 1:
 
== Maintain Collection Ordering ==
 
== Maintain Collection Ordering ==
  
In some applications it is valuable to maintain collection ordering within the Java application. JPA provides support for ordering the target of a collection mapping (OneToMany, ManyToMany) but the order is not preserved in-memory.
+
In some applications it is valuable to maintain collection ordering within the Java application. EclipseLink JPA provides support for ordering the target of a collection mapping (OneToMany, ManyToMany) but the order is not preserved in-memory.  
 +
 
 +
__TOC__
 +
 
 +
=== @OrderBy ===
 +
 
 +
In order to have a collection ordered when it is read the OrderBy configuration must be specified on the collection mapping. EclipseLink JPA will then add ORDER BY into the SQL when the collection is read in and return the initial result with this ordering. After this EclipseLink will only ensure that the collection's order as maintained by the application in a transaction is preserved when merging into the shared cache. This means that any application code modifying a collection must ensure that order is the way they want it prior to committing the changes in a transaction.
 +
 
 +
=== Re-Ordering using Events ===
 +
 
 +
=== Ordering by Index ===

Revision as of 11:49, 26 May 2008

Maintain Collection Ordering

In some applications it is valuable to maintain collection ordering within the Java application. EclipseLink JPA provides support for ordering the target of a collection mapping (OneToMany, ManyToMany) but the order is not preserved in-memory.

@OrderBy

In order to have a collection ordered when it is read the OrderBy configuration must be specified on the collection mapping. EclipseLink JPA will then add ORDER BY into the SQL when the collection is read in and return the initial result with this ordering. After this EclipseLink will only ensure that the collection's order as maintained by the application in a transaction is preserved when merging into the shared cache. This means that any application code modifying a collection must ensure that order is the way they want it prior to committing the changes in a transaction.

Re-Ordering using Events

Ordering by Index

Back to the top