HHH-951

A test and a fix for https://hibernate.atlassian.net/browse/HHH-951