Author: gbadner
Date: 2009-12-23 22:11:54 -0500 (Wed, 23 Dec 2009)
New Revision: 18322
Modified:
core/trunk/core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java
Log:
HHH-4735 : Proxy can be associated with a new session when it is already connected to a
different one (removed cached EntityKey)
Modified: core/trunk/core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java
===================================================================
---
core/trunk/core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java 2009-12-23
18:55:06 UTC (rev 18321)
+++
core/trunk/core/src/main/java/org/hibernate/proxy/AbstractLazyInitializer.java 2009-12-24
03:11:54 UTC (rev 18322)
@@ -46,7 +46,6 @@
private boolean unwrap;
private transient SessionImplementor session;
- private transient EntityKey entityKey; // cached value
/**
* For serialization from the non-pojo initializers (HHH-3309)
@@ -65,7 +64,6 @@
this.entityName = entityName;
this.id = id;
this.session = session;
- this.entityKey = generateEntityKeyOrNull();
}
/**
@@ -87,7 +85,6 @@
*/
public final void setIdentifier(Serializable id) {
this.id = id;
- entityKey = generateEntityKeyOrNull();
}
/**
@@ -118,18 +115,15 @@
}
else {
session = s;
- entityKey = generateEntityKeyOrNull();
}
}
}
- private EntityKey generateEntityKeyOrNull() {
- if ( getIdentifier() == null || session == null || entityName == null ) {
+ private static EntityKey generateEntityKeyOrNull(Serializable id, SessionImplementor s,
String entityName) {
+ if ( id == null || s == null || entityName == null ) {
return null;
}
- return new EntityKey(
- getIdentifier(), session.getFactory().getEntityPersister( entityName ),
session.getEntityMode()
- );
+ return new EntityKey( id, s.getFactory().getEntityPersister( entityName ),
s.getEntityMode() );
}
/**
@@ -137,7 +131,6 @@
*/
public void unsetSession() {
session = null;
- entityKey = null;
}
/**
@@ -183,7 +176,8 @@
}
private Object getProxyOrNull() {
- if ( session != null && session.isOpen() && entityKey != null ) {
+ final EntityKey entityKey = generateEntityKeyOrNull( getIdentifier(), session,
getEntityName() );
+ if ( entityKey != null && session != null && session.isOpen() ) {
return session.getPersistenceContext().getProxy( entityKey );
}
return null;
@@ -210,12 +204,8 @@
* do not initialize the proxy
*/
public final Object getImplementation(SessionImplementor s) throws HibernateException {
- final EntityKey entityKey = new EntityKey(
- getIdentifier(),
- s.getFactory().getEntityPersister( getEntityName() ),
- s.getEntityMode()
- );
- return s.getPersistenceContext().getEntity( entityKey );
+ final EntityKey entityKey = generateEntityKeyOrNull( getIdentifier(), s,
getEntityName() );
+ return ( entityKey == null ? null : s.getPersistenceContext().getEntity( entityKey )
);
}
/**
Show replies by date