# How to get a PersistentSortedSet?

**URL:** <https://discourse.hibernate.org/t/how-to-get-a-persistentsortedset/6629>\
**Category:** Hibernate ORM\
**Created:** [September 2, 2022, 2:18pm UTC](https://discourse.hibernate.org/t/how-to-get-a-persistentsortedset/6629 "2022-09-02T14:18:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zaleth81](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/zaleth81/32/1999_2.png) [@zaleth81](https://discourse.hibernate.org/u/zaleth81)\
**Post date:** [September 2, 2022, 2:18pm UTC](https://discourse.hibernate.org/t/how-to-get-a-persistentsortedset/6629/1 "2022-09-02T14:18:27Z")

</div>

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

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

```

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).

---

<div class="post-metadata">

**Author:** ![dreab8](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/dreab8/32/25_2.png) [@dreab8](https://discourse.hibernate.org/u/dreab8)\
**Post date:** [September 2, 2022, 2:40pm UTC](https://discourse.hibernate.org/t/how-to-get-a-persistentsortedset/6629/2 "2022-09-02T14:40:18Z")

</div>

Hi @zaleth81 ,

you have to use `sort` instead of `order-by`, you can find doc here [HIBERNATE - Relational Persistence for Idiomatic Java](https://docs.jboss.org/hibernate/core/4.3/manual/en-US/html_single/#collections-sorted)
