After upgrading to Hibernate 5.2.X we got a code fragment which triggers a NullPointerException in org.hibernate.type.EntityType.replace() after some time. The problem happens with a lazy fetching OneToMany-Attribute, multiple transactions and a few EntityManager.merge()'s.
I could break the problem down to a reproducable test case and attached it. It should explain the problem well enough.
The problem is centered around PersistentBag. If you get it in a state where PersistentBag.operationQueue is filled (initialized=false) and merge the entity in new transaction the Exception is thrown.
Hibernate 5.2.X, database independent