To specify the order of elements in a collection, use the
@OrderBy
annotation.
If the ordering element is not specified, the
JPA specification says that the ordering by the
primary key of the associated entity is assumed. Because JPA
Objects requires the use of surrogate Ids (see Section 2.3, “Specify a primary key using @Id
(not using
@IdClass
or
@EmbeddedId
)”), this basically means in insert order. For
larger collections, if you want to see the most recently added objects
at the top, then use @OrderBy
.