hibernate/hibernate-orm · error · OrderByComplianceViolation
@OrderBy expression (%s) is not a domain-model reference, wh
Error message
@OrderBy expression (%s) is not a domain-model reference, which violates the Jakarta Persistence specification - %s
What it means
Error "@OrderBy expression (%s) is not a domain-model reference, which violates the Jakarta Persistence specification - %s" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ordering/ast/ParseTreeVisitor.java:68
for ( int i = 0; i < size; i += 2 ) {
specifications.add( visitSortSpecification( (OrderingParser.SortSpecificationContext) ctx.getChild( i ) ) );
}
return specifications;
}
}
@Override
public OrderingSpecification visitSortSpecification(OrderingParser.SortSpecificationContext parsedSpec) {
assert parsedSpec != null;
assert parsedSpec.expression() != null;
final OrderingExpression orderingExpression = (OrderingExpression) parsedSpec.getChild( 0 ).accept( this );
if ( translationContext.getJpaCompliance().isJpaOrderByMappingComplianceEnabled() ) {
if ( orderingExpression instanceof DomainPath ) {
// nothing to do
}
else {
throw new OrderByComplianceViolation(
String.format(
Locale.ROOT,
"@OrderBy expression (%s) is not a domain-model reference, which violates the Jakarta Persistence specification - %s",
parsedSpec.expression().getText(),
orderingExpression.toDescriptiveText()
)
);
}
}
final OrderingSpecification result = new OrderingSpecification( orderingExpression, parsedSpec.getChild( 0 ).getText() );
int i = 1;
if ( parsedSpec.getChildCount() > i ) {
final ParseTree parseTree = parsedSpec.getChild( i );
if ( parseTree instanceof OrderingParser.CollationSpecificationContext ) {
result.setCollation( (String) parseTree.getChild( 1 ).getChild( 0 ).accept( this ) );
i++;View on GitHub (pinned to fad1729dce)
Solutions
- Rewrite the @OrderBy expression to reference domain-model attributes (e.g. 'name' or 'address.city') instead of SQL fragments or functions.
When it happens
Trigger: Thrown when an @OrderBy expression references something other than a domain-model path (e.g. a SQL function or literal), violating the JPA specification.
Common situations: See trigger scenarios.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/dcb36a63f152a78c.
Report an issue: GitHub.