Provide ability to toggle orderBy creation when entity fields are @OrderBy annotated

Description

When I use a criteria and then join entities that have properties with an @OrderBy annotation, Hibernate always creates an order by clause for this property. This leads to issues on MS SQL Server as order by properies also need to be included when distinct projections are used:

1 com.microsoft.sqlserver.jdbc.SQLServerException: ORDER BY items must appear in the select list if SELECT DISTINCT is specified.

Especially when the criteria object is assembled dynamically, the ability to manipulate the distinct projection is often not provided, so the idea is to be able to temporarily disable @OrderBys in some conditions.

Thanks in advance for an answer.

Environment

None

Status

Assignee

Unassigned

Reporter

Niko Wittenbeck

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Priority

Minor
Configure