HHH-9186

https://hibernate.atlassian.net/browse/HHH-9186

Added an unit test and bug fix for the issue.