Invalid SQL when null precedence, @OrderBy and entity graph are used

Description

Hibernate generates an invalid SQL for the case below, that basically resembles this:

(duplicate null precedence at the end)

The issue is constantly reproducible with a simple setup where you have 2 entities with a @OneToMany relation with @OrderBy annotation on the collection. Then at query time specify that relation in the entity graph hint.

I'm attaching the test scenario, it has 2 almost identical test cases:
1. With entity graph hint: Fails
2. Without entity graph hint: Succeeds

Please let me know if there is any other detail I could specify to help.

Environment

None

Assignee

Nathan Xu

Reporter

Amr Mostafa

Fix versions

Labels

None

backPortable

Backport?

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure