I'll push https://github.com/scottmarlow/hibernate-orm/tree/fix-optimiser to master and cherry-pick to 5.0. I'll be offline after today until next year