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.

Activity

Show:

Former user November 7, 2019 at 6:01 AM

Fixed in 5.3 branch as well.

Former user October 17, 2019 at 5:27 PM

Fixed in master.

Andrea Boriero September 20, 2019 at 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.

Former user September 20, 2019 at 6:27 AM

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

Fixed

Assignee

Former user(Deactivated)

Reporter

Fix versions

Affects versions

Priority

Created September 20, 2019 at 6:25 AM
Updated November 7, 2019 at 6:04 AM
Resolved November 7, 2019 at 6:01 AM
Loading...