Hibernate JPA @SortNatural Example
@SortNatural
The @SortNatural annotation is used to specify that the Set/Map should be sorted using natural sorting.SortNatural specifies in-memory Set/Map sorting using natural sorting. NOTE : Sorting is different than ordering (see OrderBy) which is applied during the SQL SELECT. For sorting based on a comparator, use SortComparator instead. It is illegal to combine SortComparator and SortNatural.
Bidirectional natural sorted set
@OneToMany(mappedBy = "person", cascade = CascadeType.ALL)@SortNatural
private SortedSet<Phone> phones = new TreeSet<>();
@SortComparator(ReverseComparator.class)
private SortedSet<Phone> phones = new TreeSet<>();
Comments
Post a Comment