Test case for https://hibernate.atlassian.net/browse/HHH-8581

I filed https://hibernate.atlassian.net/browse/HHH-8581; this pull request contains a test case demonstrating the bug.