HHH-9186

https://hibernate.atlassian.net/browse/HHH-9186

This pull request includes a unit test for the issue and a possible fix.