Possible solution I made, that seems to work at first glance. Needs more testing.
https://github.com/hibernate/hibernate-orm/pull/834