diff --git a/hibernate-core/src/main/java/org/hibernate/collection/internal/PersistentSortedMap.java b/hibernate-core/src/main/java/org/hibernate/collection/internal/PersistentSortedMap.java index 7a1761304a..2f87534397 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/internal/PersistentSortedMap.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/internal/PersistentSortedMap.java @@ -41,20 +41,22 @@ public class PersistentSortedMap extends PersistentMap implements Sort * Constructs a PersistentSortedMap. * * @param session The session + * @param comparator The sort comparator */ - public PersistentSortedMap(SharedSessionContractImplementor session) { + public PersistentSortedMap(SharedSessionContractImplementor session, Comparator comparator) { super( session ); + this.comparator = comparator; } /** * Constructs a PersistentSortedMap. * * @param session The session - * @deprecated {@link #PersistentSortedMap(SharedSessionContractImplementor)} should be used instead. + * @deprecated {@link #PersistentSortedMap(SharedSessionContractImplementor, Comparator)} should be used instead. */ @Deprecated public PersistentSortedMap(SessionImplementor session) { - this( (SharedSessionContractImplementor) session ); + this( (SharedSessionContractImplementor) session, (Comparator) null ); } /** diff --git a/hibernate-core/src/main/java/org/hibernate/collection/internal/PersistentSortedSet.java b/hibernate-core/src/main/java/org/hibernate/collection/internal/PersistentSortedSet.java index 20d46a9737..8af2ecace0 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/internal/PersistentSortedSet.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/internal/PersistentSortedSet.java @@ -38,20 +38,22 @@ public class PersistentSortedSet extends PersistentSet implements SortedSe * Constructs a PersistentSortedSet * * @param session The session + * @param comparator The sort comparator */ - public PersistentSortedSet(SharedSessionContractImplementor session) { + public PersistentSortedSet(SharedSessionContractImplementor session, Comparator comparator) { super( session ); + this.comparator = comparator; } /** * Constructs a PersistentSortedSet * * @param session The session - * @deprecated {@link #PersistentSortedSet(SharedSessionContractImplementor)} should be used instead. + * @deprecated {@link #PersistentSortedSet(SharedSessionContractImplementor, Comparator)} should be used instead. */ @Deprecated public PersistentSortedSet(SessionImplementor session) { - this( (SharedSessionContractImplementor) session ); + this( (SharedSessionContractImplementor) session, (Comparator) null ); } /** diff --git a/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardSortedMapSemantics.java b/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardSortedMapSemantics.java index 88eedc63c4..d3b79a96db 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardSortedMapSemantics.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardSortedMapSemantics.java @@ -49,9 +49,8 @@ public class StandardSortedMapSemantics extends AbstractMapSemantics result = new PersistentSortedMap<>( session ); - result.setComparator( (Comparator) collectionDescriptor.getSortingComparator() ); - return result; + //noinspection unchecked + return new PersistentSortedMap<>( session, (Comparator) collectionDescriptor.getSortingComparator() ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardSortedSetSemantics.java b/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardSortedSetSemantics.java index 86c98e7e9a..a1a62b1eca 100644 --- a/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardSortedSetSemantics.java +++ b/hibernate-core/src/main/java/org/hibernate/collection/internal/StandardSortedSetSemantics.java @@ -50,9 +50,8 @@ public class StandardSortedSetSemantics extends AbstractSetSemantics result = new PersistentSortedSet<>( session ); - result.setComparator( (Comparator) collectionDescriptor.getSortingComparator() ); - return result; + //noinspection unchecked + return new PersistentSortedSet<>( session, (Comparator) collectionDescriptor.getSortingComparator() ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/type/SortedMapType.java b/hibernate-core/src/main/java/org/hibernate/type/SortedMapType.java index 66ef7d9a93..5ee5c8d179 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/SortedMapType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/SortedMapType.java @@ -27,9 +27,7 @@ public class SortedMapType extends MapType { @Override public PersistentCollection instantiate(SharedSessionContractImplementor session, CollectionPersister persister, Object key) { - PersistentSortedMap map = new PersistentSortedMap(session); - map.setComparator(comparator); - return map; + return new PersistentSortedMap( session, comparator ); } public Class getReturnedClass() { diff --git a/hibernate-core/src/main/java/org/hibernate/type/SortedSetType.java b/hibernate-core/src/main/java/org/hibernate/type/SortedSetType.java index 9559fdc9da..34c5f03054 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/SortedSetType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/SortedSetType.java @@ -26,9 +26,7 @@ public class SortedSetType extends SetType { @Override public PersistentCollection instantiate(SharedSessionContractImplementor session, CollectionPersister persister, Object key) { - PersistentSortedSet set = new PersistentSortedSet(session); - set.setComparator(comparator); - return set; + return new PersistentSortedSet( session, comparator ); } public Class getReturnedClass() {