HHH-14537 EntityNotFoundException thrown when non-existing association with @NotFound(IGNORE) mapped has proxy in PersistenceContext

(cherry picked from commit 3c1e16e06ce7232fbe69bf1a3322d3f251a8bfbb)
This commit is contained in:
Gail Badner 2021-03-28 15:13:00 -07:00
parent 672a7e6a00
commit 106df75f20

View File

@ -367,12 +367,19 @@ private Object returnNarrowedProxy(
if ( !options.isAllowProxyCreation() ) {
impl = load( event, persister, keyToLoad, options );
if ( impl == null ) {
if ( options == LoadEventListener.INTERNAL_LOAD_NULLABLE ) {
// The proxy is for a non-existing association mapped as @NotFound.
// Don't throw an exeption; just return null.
return null;
}
else {
event.getSession()
.getFactory()
.getEntityNotFoundDelegate()
.handleEntityNotFound( persister.getEntityName(), keyToLoad.getIdentifier() );
}
}
}
return persistenceContext.narrowProxy( proxy, persister, keyToLoad, impl );
}