hibernate/hibernate-orm · error · AnnotationException
Collection ' ' is both sorted and ordered (only one of '@…
Error message
Collection '%s' is both sorted and ordered (only one of '@%s', '@%s', '@%s', and '@%s' may be used)
What it means
Mutually-exclusive-annotations guard after binding collection ordering/sorting: the collection is both sorted (in-memory comparator) and ordered (@OrderBy/@SQLOrder/@OrderColumn), which would produce conflicting semantics, so exactly one style is allowed.
Solutions
- Keep only one of the sorting/ordering annotations on the collection and remove the others.
Defensive patterns
Strategy: validation
When it happens
Trigger: A collection mapping uses an annotation or annotation combination that Hibernate forbids for collections.
Common situations: Collections carrying conflicting ordering/sorting (@Sort* vs @OrderBy/@OrderColumn), misplaced @JoinColumn, or annotations only valid for single-valued associations.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/bbddb0790228e69e.
Report an issue: GitHub.
Appendix: source
Thrown at hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java:1396
);
}
}
}
private AnnotationException buildIllegalOrderCombination() {
return new AnnotationException(
String.format(
Locale.ROOT,
"Collection '%s' is annotated both '@%s' and '@%s'",
safeCollectionRole(),
jakarta.persistence.OrderBy.class.getName(),
org.hibernate.annotations.SQLOrder.class.getName()
)
);
}
private AnnotationException buildIllegalOrderAndSortCombination() {
throw new AnnotationException(
String.format(
Locale.ROOT,
"Collection '%s' is both sorted and ordered (only one of '@%s', '@%s', '@%s', and '@%s' may be used)",
safeCollectionRole(),
jakarta.persistence.OrderBy.class.getName(),
org.hibernate.annotations.SQLOrder.class.getName(),
SortComparator.class.getName(),
SortNatural.class.getName()
)
);
}
private AnnotationException buildIllegalSortCombination() {
return new AnnotationException(
String.format(
"Collection '%s' is annotated both '@%s' and '@%s'",
safeCollectionRole(),
SortNatural.class.getName(),View on GitHub (pinned to fad1729dce)