HHH-3515 : EntityNameResolver defensiveness

git-svn-id: https://svn.jboss.org/repos/hibernate/core/branches/Branch_3_2@15271 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Steve Ebersole 2008-10-08 04:37:25 +00:00
parent 30e4a6fbfb
commit 69196be6a2
2 changed files with 30 additions and 25 deletions

View File

@ -391,6 +391,9 @@ public final class SessionFactoryImpl implements SessionFactory, SessionFactoryI
}
private void registerEntityNameResolvers(EntityPersister persister) {
if ( persister.getEntityMetamodel() == null || persister.getEntityMetamodel().getTuplizerMapping() == null ) {
return;
}
Iterator itr = persister.getEntityMetamodel().getTuplizerMapping().iterateTuplizers();
while ( itr.hasNext() ) {
final EntityTuplizer tuplizer = ( EntityTuplizer ) itr.next();

View File

@ -17,7 +17,6 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Element;
import org.hibernate.CacheMode;
import org.hibernate.ConnectionReleaseMode;
import org.hibernate.Criteria;
@ -98,7 +97,6 @@ import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
import org.hibernate.stat.SessionStatistics;
import org.hibernate.stat.SessionStatisticsImpl;
import org.hibernate.tuple.DynamicMapInstantiator;
import org.hibernate.type.Type;
import org.hibernate.util.ArrayHelper;
import org.hibernate.util.CollectionHelper;
@ -149,29 +147,7 @@ public final class SessionImpl extends AbstractSessionImpl
private transient Session rootSession;
private transient Map childSessionsByEntityMode;
private EntityNameResolver entityNameResolver = new EntityNameResolver() {
public String resolveEntityName(Object entity) {
String entityName = interceptor.getEntityName( entity );
if ( entityName != null ) {
return entityName;
}
Iterator itr = factory.iterateEntityNameResolvers( entityMode );
while ( itr.hasNext() ) {
final EntityNameResolver resolver = ( EntityNameResolver ) itr.next();
entityName = resolver.resolveEntityName( entity );
if ( entityName != null ) {
break;
}
}
if ( entityName != null ) {
return entityName;
}
// the old-time stand-by...
return entity.getClass().getName();
}
};
private EntityNameResolver entityNameResolver = new CoordinatingEntityNameResolver();
/**
* Constructor used in building "child sessions".
@ -1887,6 +1863,8 @@ public final class SessionImpl extends AbstractSessionImpl
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
log.trace( "deserializing session" );
entityNameResolver = new CoordinatingEntityNameResolver();
boolean isRootSession = ois.readBoolean();
connectionReleaseMode = ConnectionReleaseMode.parse( ( String ) ois.readObject() );
entityMode = EntityMode.parse( ( String ) ois.readObject() );
@ -1964,4 +1942,28 @@ public final class SessionImpl extends AbstractSessionImpl
oos.writeObject( enabledFilters );
oos.writeObject( childSessionsByEntityMode );
}
private class CoordinatingEntityNameResolver implements EntityNameResolver {
public String resolveEntityName(Object entity) {
String entityName = interceptor.getEntityName( entity );
if ( entityName != null ) {
return entityName;
}
Iterator itr = factory.iterateEntityNameResolvers( entityMode );
while ( itr.hasNext() ) {
final EntityNameResolver resolver = ( EntityNameResolver ) itr.next();
entityName = resolver.resolveEntityName( entity );
if ( entityName != null ) {
break;
}
}
if ( entityName != null ) {
return entityName;
}
// the old-time stand-by...
return entity.getClass().getName();
}
}
}