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

(cherry picked from commit 3c1e16e06c)
This commit is contained in:
Gail Badner 2021-03-28 15:13:00 -07:00 committed by gbadner
parent edcf4a6369
commit c2bb67515f
1 changed files with 11 additions and 4 deletions

View File

@ -385,10 +385,17 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
if ( !options.isAllowProxyCreation() ) {
impl = load( event, persister, keyToLoad, options );
if ( impl == null ) {
event.getSession()
.getFactory()
.getEntityNotFoundDelegate()
.handleEntityNotFound( persister.getEntityName(), keyToLoad.getIdentifier() );
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() );
}
}
}