master PR: https://github.com/hibernate/hibernate-orm/pull/1282
Could you please also cherry-pick fix to 5.0? Thanks