https://github.com/hibernate/hibernate-orm/pull/5540
This PR only contains the fix, not the testcase, as I’m not sure how Hibernate ORM structures tests like these.