From 3810727f5d4dbd6c0f4e8b8c84a1ef2dc1377ce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Mon, 6 Sep 2021 11:30:34 +0200 Subject: [PATCH] HHH-14811 Throw LazyInitializationException on lazy-loading an association on a deleted entity with bytecode enhancement --- .../hibernate/persister/entity/AbstractEntityPersister.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index 61a2b609ce..fbd6be9544 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -29,6 +29,7 @@ import org.hibernate.EntityMode; import org.hibernate.FetchMode; import org.hibernate.HibernateException; import org.hibernate.JDBCException; +import org.hibernate.LazyInitializationException; import org.hibernate.LockMode; import org.hibernate.LockOptions; import org.hibernate.MappingException; @@ -1149,8 +1150,9 @@ public abstract class AbstractEntityPersister // for the collection to the just loaded collection final EntityEntry ownerEntry = persistenceContext.getEntry( entity ); if ( ownerEntry == null ) { - // not good - throw new AssertionFailure( + // the entity is not in the session; it was probably deleted, + // so we cannot load the collection anymore. + throw new LazyInitializationException( "Could not locate EntityEntry for the collection owner in the PersistenceContext" ); }