NullPointerException in EntityType.replace() with a PersistentBag

Description

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.

Environment

Hibernate 5.2.X, database independent

Status

Assignee

Gail Badner

Reporter

Torsten Schöne

Fix versions

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.2.4
5.2.3

Priority

Critical