PersistenceContext can get cleared before load completes using StatelessSessionImpl

Description

When an association gets loaded eagerly by {{StatelessSessionImpl#internalLoad}} calling {{StatelessSessionImpl#get}}, {{temporaryPersistenceContext}} may get cleared before the load is complete. If this happens, Hibernate will not find an expected {{EntityEntry}}, and {{TwoPhaseLoad#afterInitialize}} will throw a {{NullPointerException}}.

The test case for caused the {{NullPointerException}} because there was a bug that caused a lazy association to be loaded eagerly. Once that bug was fixed by HHH-13633, the problem was no longer reproduced by that test case.

Modifying that test case to make the association eager reproduced this issue again.


Original description:

A test case added for throws NullPointerException.

found that this commit for caused the NPE.

Environment

None

Activity

Show:
Gail Badner
September 20, 2019, 6:27 AM

This issue does not affect 5.3 because was not backported to 5.3.

Andrea Boriero
September 20, 2019, 3:59 PM

with the Loader postpones the call to TwoPhaseLoad#afterInitialize().

What happens with a is that Loader#initilizeEntitiesAndCollection:

  • First calls TwoPhaseLoad#initilizeEntity() that triggers a call to StatelessSessionImpl#get()

that clears the PersistenceContext

  • Then calls{{TwoPhaseLoad#afterInitialize()}}

but the PersistenceContext has been previously cleared so entityEntry is null and the call to entityEntry.getPersister() causes a NPE.

Gail Badner
October 17, 2019, 5:27 PM

Fixed in master.

Gail Badner
November 7, 2019, 6:01 AM

Fixed in 5.3 branch as well.

Assignee

Gail Badner

Reporter

Gail Badner

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Major
Configure