FileDocCategorySizeDatePackage
SessionFactoryImpl.javaAPI DocHibernate 3.2.536347Wed Nov 22 05:53:54 GMT 2006org.hibernate.impl

SessionFactoryImpl

public final class SessionFactoryImpl extends Object implements org.hibernate.SessionFactory, org.hibernate.engine.SessionFactoryImplementor
Concrete implementation of the SessionFactory interface. Has the following responsibilites
  • caches configuration settings (immutably)
  • caches "compiled" mappings ie. EntityPersisters and CollectionPersisters (immutable)
  • caches "compiled" queries (memory sensitive cache)
  • manages PreparedStatements
  • delegates JDBC Connection management to the ConnectionProvider
  • factory for instances of SessionImpl
This class must appear immutable to clients, even if it does all kinds of caching and pooling under the covers. It is crucial that the class is not only thread safe, but also highly concurrent. Synchronization must be used extremely sparingly.
see
org.hibernate.connection.ConnectionProvider
see
org.hibernate.classic.Session
see
org.hibernate.hql.QueryTranslator
see
org.hibernate.persister.entity.EntityPersister
see
org.hibernate.persister.collection.CollectionPersister
author
Gavin King

Fields Summary
private final String
name
private final String
uuid
private final transient Map
entityPersisters
private final transient Map
classMetadata
private final transient Map
collectionPersisters
private final transient Map
collectionMetadata
private final transient Map
collectionRolesByEntityParticipant
private final transient Map
identifierGenerators
private final transient Map
namedQueries
private final transient Map
namedSqlQueries
private final transient Map
sqlResultSetMappings
private final transient Map
filters
private final transient Map
imports
private final transient org.hibernate.Interceptor
interceptor
private final transient org.hibernate.cfg.Settings
settings
private final transient Properties
properties
private transient org.hibernate.tool.hbm2ddl.SchemaExport
schemaExport
private final transient TransactionManager
transactionManager
private final transient org.hibernate.cache.QueryCache
queryCache
private final transient org.hibernate.cache.UpdateTimestampsCache
updateTimestampsCache
private final transient Map
queryCaches
private final transient Map
allCacheRegions
private final transient org.hibernate.stat.StatisticsImpl
statistics
private final transient org.hibernate.event.EventListeners
eventListeners
private final transient org.hibernate.context.CurrentSessionContext
currentSessionContext
private final transient org.hibernate.proxy.EntityNotFoundDelegate
entityNotFoundDelegate
private final transient org.hibernate.dialect.function.SQLFunctionRegistry
sqlFunctionRegistry
private final org.hibernate.engine.query.QueryPlanCache
queryPlanCache
private transient boolean
isClosed
private static final org.hibernate.id.IdentifierGenerator
UUID_GENERATOR
private static final Log
log
Constructors Summary
public SessionFactoryImpl(org.hibernate.cfg.Configuration cfg, org.hibernate.engine.Mapping mapping, org.hibernate.cfg.Settings settings, org.hibernate.event.EventListeners listeners)


	 
			 
	         
	         
	         
	  

		log.info("building session factory");

		this.properties = new Properties();
		this.properties.putAll( cfg.getProperties() );
		this.interceptor = cfg.getInterceptor();
		this.settings = settings;
		this.sqlFunctionRegistry = new SQLFunctionRegistry(settings.getDialect(), cfg.getSqlFunctions());
        this.eventListeners = listeners;
        this.filters = new HashMap();
		this.filters.putAll( cfg.getFilterDefinitions() );

		if ( log.isDebugEnabled() ) {
			log.debug("Session factory constructed with filter configurations : " + filters);
		}

		if ( log.isDebugEnabled() ) {
			log.debug(
					"instantiating session factory with properties: " + properties
			);
		}

		// Caches
		settings.getCacheProvider().start( properties );

		//Generators:

		identifierGenerators = new HashMap();
		Iterator classes = cfg.getClassMappings();
		while ( classes.hasNext() ) {
			PersistentClass model = (PersistentClass) classes.next();
			if ( !model.isInherited() ) {
				IdentifierGenerator generator = model.getIdentifier().createIdentifierGenerator(
						settings.getDialect(),
				        settings.getDefaultCatalogName(),
				        settings.getDefaultSchemaName(),
				        (RootClass) model
				);
				identifierGenerators.put( model.getEntityName(), generator );
			}
		}

		//Persisters:

		Map caches = new HashMap();
		entityPersisters = new HashMap();
		Map classMeta = new HashMap();
		classes = cfg.getClassMappings();
		while ( classes.hasNext() ) {
			PersistentClass model = (PersistentClass) classes.next();
			model.prepareTemporaryTables( mapping, settings.getDialect() );
			String cacheRegion = model.getRootClass().getCacheRegionName();
			CacheConcurrencyStrategy cache = (CacheConcurrencyStrategy) caches.get(cacheRegion);
			if (cache==null) {
				cache = CacheFactory.createCache(
						model.getCacheConcurrencyStrategy(),
				        cacheRegion,
				        model.isMutable(),
				        settings,
				        properties
					);
				if (cache!=null) {
					caches.put(cacheRegion, cache);
					allCacheRegions.put( cache.getRegionName(), cache.getCache() );
				}
			}
			EntityPersister cp = PersisterFactory.createClassPersister(model, cache, this, mapping);
			if ( cache != null && cache.getCache() instanceof OptimisticCache ) {
				( ( OptimisticCache ) cache.getCache() ).setSource( cp );
			}
			entityPersisters.put( model.getEntityName(), cp );
			classMeta.put( model.getEntityName(), cp.getClassMetadata() );
		}
		classMetadata = Collections.unmodifiableMap(classMeta);

		Map tmpEntityToCollectionRoleMap = new HashMap();
		collectionPersisters = new HashMap();
		Iterator collections = cfg.getCollectionMappings();
		while ( collections.hasNext() ) {
			Collection model = (Collection) collections.next();
			CacheConcurrencyStrategy cache = CacheFactory.createCache(
					model.getCacheConcurrencyStrategy(),
			    	model.getCacheRegionName(),
			    	model.isMutable(),
			    	settings,
			    	properties
			);
			if ( cache != null ) {
				allCacheRegions.put( cache.getRegionName(), cache.getCache() );
			}
			CollectionPersister persister = PersisterFactory.createCollectionPersister(cfg, model, cache, this);
			collectionPersisters.put( model.getRole(), persister.getCollectionMetadata() );
			Type indexType = persister.getIndexType();
			if ( indexType != null && indexType.isAssociationType() && !indexType.isAnyType() ) {
				String entityName = ( ( AssociationType ) indexType ).getAssociatedEntityName( this );
				Set roles = ( Set ) tmpEntityToCollectionRoleMap.get( entityName );
				if ( roles == null ) {
					roles = new HashSet();
					tmpEntityToCollectionRoleMap.put( entityName, roles );
				}
				roles.add( persister.getRole() );
			}
			Type elementType = persister.getElementType();
			if ( elementType.isAssociationType() && !elementType.isAnyType() ) {
				String entityName = ( ( AssociationType ) elementType ).getAssociatedEntityName( this );
				Set roles = ( Set ) tmpEntityToCollectionRoleMap.get( entityName );
				if ( roles == null ) {
					roles = new HashSet();
					tmpEntityToCollectionRoleMap.put( entityName, roles );
				}
				roles.add( persister.getRole() );
			}
		}
		collectionMetadata = Collections.unmodifiableMap(collectionPersisters);
		Iterator itr = tmpEntityToCollectionRoleMap.entrySet().iterator();
		while ( itr.hasNext() ) {
			final Map.Entry entry = ( Map.Entry ) itr.next();
			entry.setValue( Collections.unmodifiableSet( ( Set ) entry.getValue() ) );
		}
		collectionRolesByEntityParticipant = Collections.unmodifiableMap( tmpEntityToCollectionRoleMap );

		//Named Queries:
		namedQueries = new HashMap( cfg.getNamedQueries() );
		namedSqlQueries = new HashMap( cfg.getNamedSQLQueries() );
		sqlResultSetMappings = new HashMap( cfg.getSqlResultSetMappings() );
		imports = new HashMap( cfg.getImports() );

		// after *all* persisters and named queries are registered
		Iterator iter = entityPersisters.values().iterator();
		while ( iter.hasNext() ) {
			( (EntityPersister) iter.next() ).postInstantiate();
		}
		iter = collectionPersisters.values().iterator();
		while ( iter.hasNext() ) {
			( (CollectionPersister) iter.next() ).postInstantiate();
		}

		//JNDI + Serialization:

		name = settings.getSessionFactoryName();
		try {
			uuid = (String) UUID_GENERATOR.generate(null, null);
		}
		catch (Exception e) {
			throw new AssertionFailure("Could not generate UUID");
		}
		SessionFactoryObjectFactory.addInstance(uuid, name, this, properties);

		log.debug("instantiated session factory");

		if ( settings.isAutoCreateSchema() ) {
			new SchemaExport( cfg, settings ).create( false, true );
		}
		if ( settings.isAutoUpdateSchema() ) {
			new SchemaUpdate( cfg, settings ).execute( false, true );
		}
		if ( settings.isAutoValidateSchema() ) {
			new SchemaValidator( cfg, settings ).validate();
		}
		if ( settings.isAutoDropSchema() ) {
			schemaExport = new SchemaExport( cfg, settings );
		}

		if ( settings.getTransactionManagerLookup()!=null ) {
			log.debug("obtaining JTA TransactionManager");
			transactionManager = settings.getTransactionManagerLookup().getTransactionManager(properties);
		}
		else {
			if ( settings.getTransactionFactory().isTransactionManagerRequired() ) {
				throw new HibernateException("The chosen transaction strategy requires access to the JTA TransactionManager");
			}
			transactionManager = null;
		}

		currentSessionContext = buildCurrentSessionContext();

		if ( settings.isQueryCacheEnabled() ) {
			updateTimestampsCache = new UpdateTimestampsCache(settings, properties);
			queryCache = settings.getQueryCacheFactory()
			        .getQueryCache(null, updateTimestampsCache, settings, properties);
			queryCaches = new HashMap();
			allCacheRegions.put( updateTimestampsCache.getRegionName(), updateTimestampsCache.getCache() );
			allCacheRegions.put( queryCache.getRegionName(), queryCache.getCache() );
		}
		else {
			updateTimestampsCache = null;
			queryCache = null;
			queryCaches = null;
		}

		//checking for named queries
		if ( settings.isNamedQueryStartupCheckingEnabled() ) {
			Map errors = checkNamedQueries();
			if ( !errors.isEmpty() ) {
				Set keys = errors.keySet();
				StringBuffer failingQueries = new StringBuffer( "Errors in named queries: " );
				for ( Iterator iterator = keys.iterator() ; iterator.hasNext() ; ) {
					String queryName = ( String ) iterator.next();
					HibernateException e = ( HibernateException ) errors.get( queryName );
					failingQueries.append( queryName );
					if ( iterator.hasNext() ) {
						failingQueries.append( ", " );
					}
					log.error( "Error in named query: " + queryName, e );
				}
				throw new HibernateException( failingQueries.toString() );
			}
		}

		//stats
		getStatistics().setStatisticsEnabled( settings.isStatisticsEnabled() );

		// EntityNotFoundDelegate
		EntityNotFoundDelegate entityNotFoundDelegate = cfg.getEntityNotFoundDelegate();
		if ( entityNotFoundDelegate == null ) {
			entityNotFoundDelegate = new EntityNotFoundDelegate() {
				public void handleEntityNotFound(String entityName, Serializable id) {
					throw new ObjectNotFoundException( id, entityName );
				}
			};
		}
		this.entityNotFoundDelegate = entityNotFoundDelegate;
	
Methods Summary
private org.hibernate.context.CurrentSessionContextbuildCurrentSessionContext()

		String impl = properties.getProperty( Environment.CURRENT_SESSION_CONTEXT_CLASS );
		// for backward-compatability
		if ( impl == null && transactionManager != null ) {
			impl = "jta";
		}

		if ( impl == null ) {
			return null;
		}
		else if ( "jta".equals( impl ) ) {
			if ( settings.getTransactionFactory().areCallbacksLocalToHibernateTransactions() ) {
				log.warn( "JTASessionContext being used with JDBCTransactionFactory; auto-flush will not operate correctly with getCurrentSession()" );
			}
			return new JTASessionContext( this );
		}
		else if ( "thread".equals( impl ) ) {
			return new ThreadLocalSessionContext( this );
		}
		else if ( "managed".equals( impl ) ) {
			return new ManagedSessionContext( this );
		}
		else {
			try {
				Class implClass = ReflectHelper.classForName( impl );
				return ( CurrentSessionContext ) implClass
						.getConstructor( new Class[] { SessionFactoryImplementor.class } )
						.newInstance( new Object[] { this } );
			}
			catch( Throwable t ) {
				log.error( "Unable to construct current session context [" + impl + "]", t );
				return null;
			}
		}
	
private java.util.MapcheckNamedQueries()

		Map errors = new HashMap();

		// Check named HQL queries
		log.debug("Checking " + namedQueries.size() + " named HQL queries");
		Iterator itr = namedQueries.entrySet().iterator();
		while ( itr.hasNext() ) {
			final Map.Entry entry = ( Map.Entry ) itr.next();
			final String queryName = ( String ) entry.getKey();
			final NamedQueryDefinition qd = ( NamedQueryDefinition ) entry.getValue();
			// this will throw an error if there's something wrong.
			try {
				log.debug("Checking named query: " + queryName);
				//TODO: BUG! this currently fails for named queries for non-POJO entities
				queryPlanCache.getHQLQueryPlan( qd.getQueryString(), false, CollectionHelper.EMPTY_MAP );
			}
			catch ( QueryException e ) {
				errors.put( queryName, e );
			}
			catch ( MappingException e ) {
				errors.put( queryName, e );
			}
		}

		log.debug("Checking " + namedSqlQueries.size() + " named SQL queries");
		itr = namedSqlQueries.entrySet().iterator();
		while ( itr.hasNext() ) {
			final Map.Entry entry = ( Map.Entry ) itr.next();
			final String queryName = ( String ) entry.getKey();
			final NamedSQLQueryDefinition qd = ( NamedSQLQueryDefinition ) entry.getValue();
			// this will throw an error if there's something wrong.
			try {
				log.debug("Checking named SQL query: " + queryName);
				// TODO : would be really nice to cache the spec on the query-def so as to not have to re-calc the hash;
				// currently not doable though because of the resultset-ref stuff...
				NativeSQLQuerySpecification spec = null;
				if ( qd.getResultSetRef() != null ) {
					ResultSetMappingDefinition definition = ( ResultSetMappingDefinition )
							sqlResultSetMappings.get( qd.getResultSetRef() );
					if ( definition == null ) {
						throw new MappingException(
								"Unable to find resultset-ref definition: " + qd.getResultSetRef()
							);
					}
					spec = new NativeSQLQuerySpecification(
							qd.getQueryString(),
					        definition.getQueryReturns(),
					        qd.getQuerySpaces()
					);
				}
				else
				{
					spec =  new NativeSQLQuerySpecification(
							qd.getQueryString(),
					        qd.getQueryReturns(),
					        qd.getQuerySpaces()
					);
				}
				queryPlanCache.getNativeSQLQueryPlan( spec );
			}
			catch ( QueryException e ) {
				errors.put( queryName, e );
			}
			catch ( MappingException e ) {
				errors.put( queryName, e );
			}
		}

		return errors;
	
public voidclose()
Closes the session factory, releasing all held resources.
  1. cleans up used cache regions and "stops" the cache provider.
  2. close the JDBC connection
  3. remove the JNDI binding
Note: Be aware that the sessionfactory instance still can be a "heavy" object memory wise after close() has been called. Thus it is important to not keep referencing the instance to let the garbage collector release the memory.


		log.info("closing");

		isClosed = true;

		Iterator iter = entityPersisters.values().iterator();
		while ( iter.hasNext() ) {
			EntityPersister p = (EntityPersister) iter.next();
			if ( p.hasCache() ) {
				p.getCache().destroy();
			}
		}

		iter = collectionPersisters.values().iterator();
		while ( iter.hasNext() ) {
			CollectionPersister p = (CollectionPersister) iter.next();
			if ( p.hasCache() ) {
				p.getCache().destroy();
			}
		}

		if ( settings.isQueryCacheEnabled() )  {
			queryCache.destroy();

			iter = queryCaches.values().iterator();
			while ( iter.hasNext() ) {
				QueryCache cache = (QueryCache) iter.next();
				cache.destroy();
			}
			updateTimestampsCache.destroy();
		}

		settings.getCacheProvider().stop();

		try {
			settings.getConnectionProvider().close();
		}
		finally {
			SessionFactoryObjectFactory.removeInstance(uuid, name, properties);
		}

		if ( settings.isAutoDropSchema() ) {
			schemaExport.drop( false, true );
		}

	
static org.hibernate.impl.SessionFactoryImpldeserialize(java.io.ObjectInputStream ois)
Custom deserialization hook used during Session deserialization.

param
ois The stream from which to "read" the factory
throws
IOException

		String uuid = ois.readUTF();
		boolean isNamed = ois.readBoolean();
		String name = null;
		if ( isNamed ) {
			name = ois.readUTF();
		}
		Object result = SessionFactoryObjectFactory.getInstance( uuid );
		if ( result == null ) {
			log.trace( "could not locate session factory by uuid [" + uuid + "] during session deserialization; trying name" );
			if ( isNamed ) {
				result = SessionFactoryObjectFactory.getNamedInstance( name );
			}
			if ( result == null ) {
				throw new InvalidObjectException( "could not resolve session factory during session deserialization [uuid=" + uuid + ", name=" + name + "]" );
			}
		}
		return ( SessionFactoryImpl ) result;
	
public voidevict(java.lang.Class persistentClass, java.io.Serializable id)

		EntityPersister p = getEntityPersister( persistentClass.getName() );
		if ( p.hasCache() ) {
			if ( log.isDebugEnabled() ) {
				log.debug( "evicting second-level cache: " + MessageHelper.infoString(p, id, this) );
			}
			CacheKey cacheKey = new CacheKey( id, p.getIdentifierType(), p.getRootEntityName(), EntityMode.POJO, this );
			p.getCache().remove( cacheKey );
		}
	
public voidevict(java.lang.Class persistentClass)

		EntityPersister p = getEntityPersister( persistentClass.getName() );
		if ( p.hasCache() ) {
			if ( log.isDebugEnabled() ) {
				log.debug( "evicting second-level cache: " + p.getEntityName() );
			}
			p.getCache().clear();
		}
	
public voidevictCollection(java.lang.String roleName, java.io.Serializable id)

		CollectionPersister p = getCollectionPersister(roleName);
		if ( p.hasCache() ) {
			if ( log.isDebugEnabled() ) {
				log.debug( "evicting second-level cache: " + MessageHelper.collectionInfoString(p, id, this) );
			}
			CacheKey cacheKey = new CacheKey( id, p.getKeyType(), p.getRole(), EntityMode.POJO, this );
			p.getCache().remove( cacheKey );
		}
	
public voidevictCollection(java.lang.String roleName)

		CollectionPersister p = getCollectionPersister(roleName);
		if ( p.hasCache() ) {
			if ( log.isDebugEnabled() ) {
				log.debug( "evicting second-level cache: " + p.getRole() );
			}
			p.getCache().clear();
		}
	
public voidevictEntity(java.lang.String entityName, java.io.Serializable id)

		EntityPersister p = getEntityPersister(entityName);
		if ( p.hasCache() ) {
			if ( log.isDebugEnabled() ) {
				log.debug( "evicting second-level cache: " + MessageHelper.infoString(p, id, this) );
			}
			CacheKey cacheKey = new CacheKey( id, p.getIdentifierType(), p.getRootEntityName(), EntityMode.POJO, this );
			p.getCache().remove( cacheKey );
		}
	
public voidevictEntity(java.lang.String entityName)

		EntityPersister p = getEntityPersister(entityName);
		if ( p.hasCache() ) {
			if ( log.isDebugEnabled() ) {
				log.debug( "evicting second-level cache: " + p.getEntityName() );
			}
			p.getCache().clear();
		}
	
public voidevictQueries()

		if ( settings.isQueryCacheEnabled() ) {
			queryCache.clear();
		}
	
public voidevictQueries(java.lang.String cacheRegion)

		if (cacheRegion==null) {
			throw new NullPointerException("use the zero-argument form to evict the default query cache");
		}
		else {
			synchronized (allCacheRegions) {
				if ( settings.isQueryCacheEnabled() ) {
					QueryCache currentQueryCache = (QueryCache) queryCaches.get(cacheRegion);
					if ( currentQueryCache != null ) {
						currentQueryCache.clear();
					}
				}
			}
		}
	
public java.util.MapgetAllClassMetadata()

		return classMetadata;
	
public java.util.MapgetAllCollectionMetadata()

		return collectionMetadata;
	
public java.util.MapgetAllSecondLevelCacheRegions()

		synchronized (allCacheRegions) {
			return new HashMap(allCacheRegions);
		}
	
public org.hibernate.jdbc.BatcherFactorygetBatcherFactory()

		return settings.getBatcherFactory();
	
public org.hibernate.metadata.ClassMetadatagetClassMetadata(java.lang.Class persistentClass)

		return getClassMetadata( persistentClass.getName() );
	
public org.hibernate.metadata.ClassMetadatagetClassMetadata(java.lang.String entityName)

		return (ClassMetadata) classMetadata.get(entityName);
	
public org.hibernate.metadata.CollectionMetadatagetCollectionMetadata(java.lang.String roleName)

		return (CollectionMetadata) collectionMetadata.get(roleName);
	
public org.hibernate.persister.collection.CollectionPersistergetCollectionPersister(java.lang.String role)

		CollectionPersister result = (CollectionPersister) collectionPersisters.get(role);
		if (result==null) {
			throw new MappingException( "Unknown collection role: " + role );
		}
		return result;
	
public java.util.SetgetCollectionRolesByEntityParticipant(java.lang.String entityName)

		return ( Set ) collectionRolesByEntityParticipant.get( entityName );
	
public org.hibernate.connection.ConnectionProvidergetConnectionProvider()

		return settings.getConnectionProvider();
	
public org.hibernate.classic.SessiongetCurrentSession()

		if ( currentSessionContext == null ) {
			throw new HibernateException( "No CurrentSessionContext configured!" );
		}
		return currentSessionContext.currentSession();
	
public java.util.SetgetDefinedFilterNames()

		return filters.keySet();
	
public org.hibernate.dialect.DialectgetDialect()

		return settings.getDialect();
	
public org.hibernate.proxy.EntityNotFoundDelegategetEntityNotFoundDelegate()

		return entityNotFoundDelegate;
	
public org.hibernate.persister.entity.EntityPersistergetEntityPersister(java.lang.String entityName)

		EntityPersister result = (EntityPersister) entityPersisters.get(entityName);
		if (result==null) {
			throw new MappingException( "Unknown entity: " + entityName );
		}
		return result;
	
public org.hibernate.event.EventListenersgetEventListeners()

		return eventListeners;
	
public org.hibernate.engine.FilterDefinitiongetFilterDefinition(java.lang.String filterName)

		FilterDefinition def = ( FilterDefinition ) filters.get( filterName );
		if ( def == null ) {
			throw new HibernateException( "No such filter configured [" + filterName + "]" );
		}
		return def;
	
public org.hibernate.id.IdentifierGeneratorgetIdentifierGenerator(java.lang.String rootEntityName)

		return (IdentifierGenerator) identifierGenerators.get(rootEntityName);
	
public java.lang.StringgetIdentifierPropertyName(java.lang.String className)

		return getEntityPersister(className).getIdentifierPropertyName();
	
public org.hibernate.type.TypegetIdentifierType(java.lang.String className)

		return getEntityPersister(className).getIdentifierType();
	
public java.lang.String[]getImplementors(java.lang.String className)
Return the names of all persistent (mapped) classes that extend or implement the given class or interface, accounting for implicit/explicit polymorphism settings and excluding mapped subclasses/joined-subclasses of other classes in the result.


		final Class clazz;
		try {
			clazz = ReflectHelper.classForName(className);
		}
		catch (ClassNotFoundException cnfe) {
			return new String[] { className }; //for a dynamic-class
		}

		ArrayList results = new ArrayList();
		Iterator iter = entityPersisters.values().iterator();
		while ( iter.hasNext() ) {
			//test this entity to see if we must query it
			EntityPersister testPersister = (EntityPersister) iter.next();
			if ( testPersister instanceof Queryable ) {
				Queryable testQueryable = (Queryable) testPersister;
				String testClassName = testQueryable.getEntityName();
				boolean isMappedClass = className.equals(testClassName);
				if ( testQueryable.isExplicitPolymorphism() ) {
					if ( isMappedClass ) {
						return new String[] {className}; //NOTE EARLY EXIT
					}
				}
				else {
					if (isMappedClass) {
						results.add(testClassName);
					}
					else {
						final Class mappedClass = testQueryable.getMappedClass( EntityMode.POJO );
						if ( mappedClass!=null && clazz.isAssignableFrom( mappedClass ) ) {
							final boolean assignableSuperclass;
							if ( testQueryable.isInherited() ) {
								Class mappedSuperclass = getEntityPersister( testQueryable.getMappedSuperclass() ).getMappedClass( EntityMode.POJO);
								assignableSuperclass = clazz.isAssignableFrom(mappedSuperclass);
							}
							else {
								assignableSuperclass = false;
							}
							if ( !assignableSuperclass ) {
								results.add( testClassName );
							}
						}
					}
				}
			}
		}
		return (String[]) results.toArray( new String[ results.size() ] );
	
public java.lang.StringgetImportedClassName(java.lang.String className)

		String result = (String) imports.get(className);
		if (result==null) {
			try {
				ReflectHelper.classForName(className);
				return className;
			}
			catch (ClassNotFoundException cnfe) {
				return null;
			}
		}
		else {
			return result;
		}
	
public org.hibernate.InterceptorgetInterceptor()

		return interceptor;
	
public org.hibernate.engine.NamedQueryDefinitiongetNamedQuery(java.lang.String queryName)

		return (NamedQueryDefinition) namedQueries.get(queryName);
	
public org.hibernate.engine.NamedSQLQueryDefinitiongetNamedSQLQuery(java.lang.String queryName)

		return (NamedSQLQueryDefinition) namedSqlQueries.get(queryName);
	
public org.hibernate.cache.QueryCachegetQueryCache()

		return queryCache;
	
public org.hibernate.cache.QueryCachegetQueryCache(java.lang.String cacheRegion)

		if (cacheRegion==null) {
			return getQueryCache();
		}

		if ( !settings.isQueryCacheEnabled() ) {
			return null;
		}

		synchronized (allCacheRegions) {
			QueryCache currentQueryCache = (QueryCache) queryCaches.get(cacheRegion);
			if (currentQueryCache==null) {
				currentQueryCache = settings.getQueryCacheFactory()
					.getQueryCache(cacheRegion, updateTimestampsCache, settings, properties);
				queryCaches.put(cacheRegion, currentQueryCache);
				allCacheRegions.put( currentQueryCache.getRegionName(), currentQueryCache.getCache() );
			}
			return currentQueryCache;
		}
	
public org.hibernate.engine.query.QueryPlanCachegetQueryPlanCache()

		return queryPlanCache;
	
public javax.naming.ReferencegetReference()

		log.debug("Returning a Reference to the SessionFactory");
		return new Reference(
			SessionFactoryImpl.class.getName(),
		    new StringRefAddr("uuid", uuid),
		    SessionFactoryObjectFactory.class.getName(),
		    null
		);
	
public org.hibernate.type.TypegetReferencedPropertyType(java.lang.String className, java.lang.String propertyName)

		return getEntityPersister(className).getPropertyType(propertyName);
	
public org.hibernate.engine.ResultSetMappingDefinitiongetResultSetMapping(java.lang.String resultSetName)

		return (ResultSetMappingDefinition) sqlResultSetMappings.get(resultSetName);
	
public java.lang.String[]getReturnAliases(java.lang.String queryString)

		return queryPlanCache.getHQLQueryPlan( queryString, false, CollectionHelper.EMPTY_MAP ).getReturnMetadata().getReturnAliases();
	
public org.hibernate.type.Type[]getReturnTypes(java.lang.String queryString)

		return queryPlanCache.getHQLQueryPlan( queryString, false, CollectionHelper.EMPTY_MAP ).getReturnMetadata().getReturnTypes();
	
public org.hibernate.exception.SQLExceptionConvertergetSQLExceptionConverter()

		return settings.getSQLExceptionConverter();
	
public org.hibernate.cache.CachegetSecondLevelCacheRegion(java.lang.String regionName)

		synchronized (allCacheRegions) {
			return (Cache) allCacheRegions.get(regionName);
		}
	
public org.hibernate.cfg.SettingsgetSettings()

		return settings;
	
public org.hibernate.dialect.function.SQLFunctionRegistrygetSqlFunctionRegistry()

		return sqlFunctionRegistry;
	
public org.hibernate.stat.StatisticsgetStatistics()

		return statistics;
	
public org.hibernate.stat.StatisticsImplementorgetStatisticsImplementor()

		return statistics;
	
public org.hibernate.transaction.TransactionFactorygetTransactionFactory()

		return settings.getTransactionFactory();
	
public javax.transaction.TransactionManagergetTransactionManager()

		return transactionManager;
	
public org.hibernate.cache.UpdateTimestampsCachegetUpdateTimestampsCache()

		return updateTimestampsCache;
	
public booleanisClosed()

		return isClosed;
	
public org.hibernate.classic.SessionopenSession()

		return openSession(interceptor);
	
public org.hibernate.classic.SessionopenSession(java.sql.Connection connection, boolean flushBeforeCompletionEnabled, boolean autoCloseSessionEnabled, org.hibernate.ConnectionReleaseMode connectionReleaseMode)

		return new SessionImpl(
				connection,
		        this,
		        true,
		        settings.getCacheProvider().nextTimestamp(),
		        interceptor,
		        settings.getDefaultEntityMode(),
		        flushBeforeCompletionEnabled,
		        autoCloseSessionEnabled,
		        connectionReleaseMode
			);
	
private SessionImplopenSession(java.sql.Connection connection, boolean autoClose, long timestamp, org.hibernate.Interceptor sessionLocalInterceptor)

		return new SessionImpl(
		        connection,
		        this,
		        autoClose,
		        timestamp,
		        sessionLocalInterceptor == null ? interceptor : sessionLocalInterceptor,
		        settings.getDefaultEntityMode(),
		        settings.isFlushBeforeCompletionEnabled(),
		        settings.isAutoCloseSessionEnabled(),
		        settings.getConnectionReleaseMode()
			);
	
public org.hibernate.classic.SessionopenSession(java.sql.Connection connection, org.hibernate.Interceptor sessionLocalInterceptor)

		return openSession(connection, false, Long.MIN_VALUE, sessionLocalInterceptor);
	
public org.hibernate.classic.SessionopenSession(org.hibernate.Interceptor sessionLocalInterceptor)

		// note that this timestamp is not correct if the connection provider
		// returns an older JDBC connection that was associated with a
		// transaction that was already begun before openSession() was called
		// (don't know any possible solution to this!)
		long timestamp = settings.getCacheProvider().nextTimestamp();
		return openSession( null, true, timestamp, sessionLocalInterceptor );
	
public org.hibernate.classic.SessionopenSession(java.sql.Connection connection)

		return openSession(connection, interceptor); //prevents this session from adding things to cache
	
public org.hibernate.StatelessSessionopenStatelessSession()

		return new StatelessSessionImpl( null, this );
	
public org.hibernate.StatelessSessionopenStatelessSession(java.sql.Connection connection)

		return new StatelessSessionImpl( connection, this );
	
public org.hibernate.classic.SessionopenTemporarySession()

		return new SessionImpl(
				null,
		        this,
		        true,
		        settings.getCacheProvider().nextTimestamp(),
		        interceptor,
		        settings.getDefaultEntityMode(),
		        false,
		        false,
		        ConnectionReleaseMode.AFTER_STATEMENT
			);
	
private final voidreadObject(java.io.ObjectInputStream in)

		log.trace("deserializing");
		in.defaultReadObject();
		log.debug("deserialized: " + uuid);
	
private java.lang.ObjectreadResolve()

		log.trace("Resolving serialized SessionFactory");
		// look for the instance by uuid
		Object result = SessionFactoryObjectFactory.getInstance(uuid);
		if (result==null) {
			// in case we were deserialized in a different JVM, look for an instance with the same name
			// (alternatively we could do an actual JNDI lookup here....)
			result = SessionFactoryObjectFactory.getNamedInstance(name);
			if (result==null) {
				throw new InvalidObjectException("Could not find a SessionFactory named: " + name);
			}
			else {
				log.debug("resolved SessionFactory by name");
			}
		}
		else {
			log.debug("resolved SessionFactory by uid");
		}
		return result;
	
voidserialize(java.io.ObjectOutputStream oos)
Custom serialization hook used during Session serialization.

param
oos The stream to which to write the factory
throws
IOException

		oos.writeUTF( uuid );
		oos.writeBoolean( name != null );
		if ( name != null ) {
			oos.writeUTF( name );
		}
	
private final voidwriteObject(java.io.ObjectOutputStream out)

		log.debug("serializing: " + uuid);
		out.defaultWriteObject();
		log.trace("serialized");