I would like to use a SortedSet as a Collection with Spring JPA…
@SortNatural
@ElementCollection
private SortedSet<Report> activities = new TreeSet<>();
but Spring only let's me specify [Collection, List and Set].
I mean Set does work, Hibernate internally uses a wrapper class called PersistentSortedSet when I add the @SortNatural annotation, but I also want to use methods SortedSet provides, like last(). Specifing SortedSet doesn't let me compile and a cast from Set to TreeSet (SortedSet) doesn't work either.
((TreeSet<Report>) repairableActivities).last();
Exception:
java.lang.ClassCastException: class org.hibernate.collection.internal.PersistentSortedSet cannot be cast to class java.util.TreeSet (org.hibernate.collection.internal.PersistentSortedSet is in unnamed module of loader 'app'; java.util.TreeSet is in module java.base of loader 'bootstrap')
I found threads with similar issues (Changing from Collection to SortedSet) but there was no real solution.
Thank you in advance