How to get a PersistentSortedSet?

We would like to use SortedSet in order to list them in alphabetic order after adding new Materials, but when we set the variable to SortedSet and try to load materials from the database, we get an IllegalArgumentException: Expected type: java.util.SortedSet, actual value: org.hibernate.collection.internal.PersistentSet. The mapping in our HBM file is

        <set cascade="save-update" lazy="true" name="rawMaterials" order-by="name">
            <key column="RM_GROUP_ID"/>
            <one-to-many class="Material"/>

How do we tell Hibernate to use PersistentSortedSet instead of PersistentSet? What I found on StackOverflow indicates that order-by should be enough (our Material class implements Comparable).

Hi @zaleth81 ,

you have to use sort instead of order-by, you can find doc here HIBERNATE - Relational Persistence for Idiomatic Java

1 Like