HHH-14811 Throw LazyInitializationException on lazy-loading an association on a deleted entity with bytecode enhancement

This commit is contained in:
Yoann Rodière 2021-09-06 11:30:34 +02:00 committed by Sanne Grinovero
parent 30a5acf741
commit 3810727f5d
1 changed files with 4 additions and 2 deletions

View File

@ -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"
);
}