From 16577020158a4ce1c3fbd78392b30da06e5ceca3 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Sun, 28 Apr 2024 14:10:10 +0200 Subject: [PATCH] HHH-18024 fix getLockMode() on read-only entity it resulted in spurious exception claiming entity was deleted Signed-off-by: Gavin King --- .../src/main/java/org/hibernate/internal/SessionImpl.java | 2 +- .../java/org/hibernate/loader/ast/internal/LoaderHelper.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java index 88015b421a..3297cdc8c8 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java @@ -560,7 +560,7 @@ public class SessionImpl throw new TransientObjectException( "Given object not associated with the session" ); } - if ( e.getStatus() != Status.MANAGED ) { + if ( e.getStatus().isDeletedOrGone() ) { throw new ObjectDeletedException( "The given object was deleted", e.getId(), diff --git a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderHelper.java b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderHelper.java index f2c0763412..d6e2fc51b1 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/LoaderHelper.java @@ -19,7 +19,6 @@ import org.hibernate.engine.spi.EntityEntry; import org.hibernate.engine.spi.LoadQueryInfluencers; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.engine.spi.Status; import org.hibernate.engine.spi.SubselectFetch; import org.hibernate.event.spi.EventSource; import org.hibernate.loader.LoaderLogging; @@ -55,7 +54,7 @@ public class LoaderHelper { // The user requested a "greater" (i.e. more restrictive) form of // pessimistic lock - if ( entry.getStatus() != Status.MANAGED ) { + if ( entry.getStatus().isDeletedOrGone()) { throw new ObjectDeletedException( "attempted to lock a deleted instance", entry.getId(),