From 6abbd54e8ee5f61b1a6ee79dfbeb1d10f0a1e9d0 Mon Sep 17 00:00:00 2001 From: Gail Badner Date: Wed, 10 Feb 2010 07:03:48 +0000 Subject: [PATCH] HHH-4896 : Read-only proxy targets initialized from second-level cache are not read-only git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18759 1b8cb986-b30d-0410-93ca-fae66ebed9b2 --- .../event/def/DefaultLoadEventListener.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/hibernate/event/def/DefaultLoadEventListener.java b/core/src/main/java/org/hibernate/event/def/DefaultLoadEventListener.java index f301ea1887..95bbbabf91 100644 --- a/core/src/main/java/org/hibernate/event/def/DefaultLoadEventListener.java +++ b/core/src/main/java/org/hibernate/event/def/DefaultLoadEventListener.java @@ -635,8 +635,9 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i session.instantiate( subclassPersister, id ) : optionalObject; // make it circular-reference safe + EntityKey entityKey = new EntityKey( id, subclassPersister, session.getEntityMode() ); TwoPhaseLoad.addUninitializedCachedEntity( - new EntityKey( id, subclassPersister, session.getEntityMode() ), + entityKey, result, subclassPersister, LockMode.NONE, @@ -659,12 +660,21 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i if ( log.isTraceEnabled() ) log.trace( "Cached Version: " + version ); final PersistenceContext persistenceContext = session.getPersistenceContext(); + boolean isReadOnly = session.isDefaultReadOnly(); + if ( persister.isMutable() ) { + Object proxy = persistenceContext.getProxy( entityKey ); + if ( proxy != null ) { + // there is already a proxy for this impl + // only set the status to read-only if the proxy is read-only + isReadOnly = ( ( HibernateProxy ) proxy ).getHibernateLazyInitializer().isReadOnly(); + } + } + else { + isReadOnly = true; + } persistenceContext.addEntry( result, - ( session.isDefaultReadOnly() || ! persister.isMutable() ? - Status.READ_ONLY : - Status.MANAGED - ), + ( isReadOnly ? Status.READ_ONLY : Status.MANAGED ), values, null, id,