diff --git a/hibernate-core/src/main/antlr/sql-gen.g b/hibernate-core/src/main/antlr/sql-gen.g index bbc2e5d021..b59667c796 100644 --- a/hibernate-core/src/main/antlr/sql-gen.g +++ b/hibernate-core/src/main/antlr/sql-gen.g @@ -199,7 +199,7 @@ orderExprs { String ordExp = null; String ordDir = null; String ordNul = null; } (dir:orderDirection { ordDir = #dir.getText(); })? (ordNul=nullOrdering)? // SQL Tokens can be passed through as-is. // These tokens could be mapping defined order by fragments which are already rendered via the dialect hook - { out( #e.getType() == SQL_TOKEN ? ordExp : renderOrderByElement( ordExp, ordDir, ordNul ) ); } + { out( #e.getType() == SQL_TOKEN && ordDir == null && ordNul == null ? ordExp : renderOrderByElement( ordExp, ordDir, ordNul ) ); } ( {out(", "); } orderExprs )? ;