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
This commit is contained in:
parent
b39918f247
commit
6abbd54e8e
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue