We're updating the issue view to help you get more done. 

@SortNatural and @SortComparator not working.

Description

When using the @SortNatural annotation, the application fails with the exception:

Caused by: org.hibernate.AnnotationException: A sorted collection must define and ordering or sorting : com.doblones.data.StockSummarySegment.summaries
at org.hibernate.cfg.annotations.CollectionBinder.applySortingAndOrdering(CollectionBinder.java:603)
at org.hibernate.cfg.annotations.CollectionBinder.bind(CollectionBinder.java:447)
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:2027)
at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:834)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:753)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3762)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3716)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1410)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
... 53 more

Code is:

@OneToMany(mappedBy = "segment", fetch = FetchType.EAGER, cascade = {CascadeType.ALL})
@SortNatural
private SortedSet<StockSummary> summaries;

If I revert to the deprecated @Sort annotation, it works fine.

Environment

JPA 2.1, Glassfish 4.

Status

Assignee

Brett Meyer

Reporter

Juan Arjona

Fix versions

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

4.3.0.Final

Priority

Major