From 4c110150e488a865bb26e4fad885ac1181161869 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Wed, 8 Oct 2008 04:39:11 +0000 Subject: [PATCH] HHH-3515 : EntityNameResolver defensiveness git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@15273 1b8cb986-b30d-0410-93ca-fae66ebed9b2 --- .../hibernate/impl/SessionFactoryImpl.java | 3 ++ .../java/org/hibernate/impl/SessionImpl.java | 54 +++++++++---------- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java b/core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java index 2a924736fb..c657398b25 100644 --- a/core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java +++ b/core/src/main/java/org/hibernate/impl/SessionFactoryImpl.java @@ -468,6 +468,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(); diff --git a/core/src/main/java/org/hibernate/impl/SessionImpl.java b/core/src/main/java/org/hibernate/impl/SessionImpl.java index 0b277a6ca8..b119ccf53c 100644 --- a/core/src/main/java/org/hibernate/impl/SessionImpl.java +++ b/core/src/main/java/org/hibernate/impl/SessionImpl.java @@ -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; @@ -73,7 +72,6 @@ import org.hibernate.engine.ActionQueue; import org.hibernate.engine.CollectionEntry; import org.hibernate.engine.EntityEntry; import org.hibernate.engine.EntityKey; -import org.hibernate.engine.FilterDefinition; import org.hibernate.engine.PersistenceContext; import org.hibernate.engine.QueryParameters; import org.hibernate.engine.StatefulPersistenceContext; @@ -127,8 +125,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.tuple.entity.PojoEntityTuplizer; import org.hibernate.type.Type; import org.hibernate.util.ArrayHelper; import org.hibernate.util.CollectionHelper; @@ -177,29 +173,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". @@ -1944,6 +1918,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() ); @@ -2020,4 +1996,28 @@ public final class SessionImpl extends AbstractSessionImpl oos.writeObject( loadQueryInfluencers ); 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(); + } + } }