HHH-3515 : EntityNameResolver defensiveness

git-svn-id: https://svn.jboss.org/repos/hibernate/core/branches/Branch_3_3@15272 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Steve Ebersole 2008-10-08 04:38:55 +00:00
parent c6f995e23e
commit b7a3ee8b15
2 changed files with 30 additions and 25 deletions

View File

@ -426,6 +426,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

@ -39,7 +39,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.dom4j.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -125,7 +124,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;
@ -176,29 +174,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".
@ -1924,6 +1900,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() );
@ -2001,4 +1979,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();
}
}
}