3.8.7.6.3. Order Column

Relational databases do not guarantee that records are returned in insertion order. If you want to make sure that your collection elements are loaded in the same order they were in when last stored, you must declare an order column. An order column can be declared using OpenJPA’s org.apache.openjpa.persistence.jdbc.OrderColumn annotation or the JPA 2.0 jakarta.persistence.OrderColumn annotation or order-column orm element as defined in XML Schema. OpenJPA’s org.apache.openjpa.persistence.jdbc.OrderColumn annotation has the following properties:

  • String name: Defaults to the name of the relationship property or field of the entity or embeddable class + _ORDER. To use the JPA 1.0 default order column name ORDR, set the openjpa.Compatibility option UseJPA2DefaultOrderColumnName to false.

  • boolean enabled

  • int precision

  • String columnDefinition

  • boolean insertable

  • boolean updatable

Order columns are always in the container table. You can explicitly turn off ordering (if you have enabled it by default via your mapping defaults) by setting the enabled property to false. All other properties correspond exactly to the same-named properties on the standard Column annotation, described in Column.