org.hibernate
Interface SessionFactory

All Superinterfaces:
Referenceable, Serializable
All Known Subinterfaces:
SessionFactoryImplementor
All Known Implementing Classes:
SessionFactoryImpl, SessionFactoryStub

public interface SessionFactory
extends Referenceable, Serializable

Creates Sessions. Usually an application has a single SessionFactory. Threads servicing client requests obtain Sessions from the factory.

Implementors must be threadsafe.

SessionFactorys are immutable. The behaviour of a SessionFactory is controlled by properties supplied at configuration time. These properties are defined on Environment.

Author:
Gavin King
See Also:
Session, Environment, Configuration, ConnectionProvider, TransactionFactory

Method Summary
 void close()
          Destroy this SessionFactory and release all resources (caches, connection pools, etc).
 void evict(Class persistentClass)
          Evict all entries from the second-level cache.
 void evict(Class persistentClass, Serializable id)
          Evict an entry from the second-level cache.
 void evictCollection(String roleName)
          Evict all entries from the second-level cache.
 void evictCollection(String roleName, Serializable id)
          Evict an entry from the second-level cache.
 void evictEntity(String entityName)
          Evict all entries from the second-level cache.
 void evictEntity(String entityName, Serializable id)
          Evict an entry from the second-level cache.
 void evictQueries()
          Evict any query result sets cached in the default query cache region.
 void evictQueries(String cacheRegion)
          Evict any query result sets cached in the named query cache region.
 Map getAllClassMetadata()
          Get all ClassMetadata as a Map from entityname String to metadata object
 Map getAllCollectionMetadata()
          Get all CollectionMetadata as a Map from role name to metadata object
 ClassMetadata getClassMetadata(Class persistentClass)
          Get the ClassMetadata associated with the given entity class
 ClassMetadata getClassMetadata(String entityName)
          Get the ClassMetadata associated with the given entity name
 CollectionMetadata getCollectionMetadata(String roleName)
          Get the CollectionMetadata associated with the named collection role
 Session getCurrentSession()
          Obtains the current session, where "current" is maintained in relation to the current JTA transaction; if a Session is not already associated with the current JTA transaction, a new Session will be opened and it will be associated with that JTA transaction.
 Statistics getStatistics()
          Get the statistics for this session factory
 boolean isClosed()
          Was this SessionFactory already closed?
 Session openSession()
          Create database connection and open a Session on it.
 Session openSession(Connection connection)
          Open a Session on the given connection.
 Session openSession(Connection connection, Interceptor interceptor)
          Open a Session on the given connection, specifying an interceptor.
 Session openSession(Interceptor interceptor)
          Create database connection and open a Session on it, specifying an interceptor.
 
Methods inherited from interface javax.naming.Referenceable
getReference
 

Method Detail

openSession

public Session openSession(Connection connection)
Open a Session on the given connection.

Note that the second-level cache will be disabled if you supply a JDBC connection. Hibernate will not be able to track any statements you might have executed in the same transaction. Consider implementing your own ConnectionProvider.

Parameters:
connection - a connection provided by the application.
Returns:
Session

openSession

public Session openSession(Interceptor interceptor)
                    throws HibernateException
Create database connection and open a Session on it, specifying an interceptor.

Parameters:
interceptor - a session-scoped interceptor
Returns:
Session
Throws:
HibernateException

openSession

public Session openSession(Connection connection,
                           Interceptor interceptor)
Open a Session on the given connection, specifying an interceptor.

Note that the second-level cache will be disabled if you supply a JDBC connection. Hibernate will not be able to track any statements you might have executed in the same transaction. Consider implementing your own ConnectionProvider.

Parameters:
connection - a connection provided by the application.
interceptor - a session-scoped interceptor
Returns:
Session

openSession

public Session openSession()
                    throws HibernateException
Create database connection and open a Session on it.

Returns:
Session
Throws:
HibernateException

getCurrentSession

public Session getCurrentSession()
                          throws HibernateException
Obtains the current session, where "current" is maintained in relation to the current JTA transaction; if a Session is not already associated with the current JTA transaction, a new Session will be opened and it will be associated with that JTA transaction.

This is only useful in managed environments where Hibernate has access to the TransactionManager for the given environment. A Transaction must also already be in effect prior to calls to this method. If either condition fails, an exception is thrown.

The Sessions returned from this method are automatically configured with both the auto-flush and auto-close attributes set to true, meaning that the Session will be automatically flushed and closed as part of the lifecycle for the JTA transaction to which it is associated.

Returns:
The current session.
Throws:
HibernateException - Indicates that either
  • could not locate transaction manager
  • no transaction in effect
  • problems opening a session to associate with the transaction

getClassMetadata

public ClassMetadata getClassMetadata(Class persistentClass)
                               throws HibernateException
Get the ClassMetadata associated with the given entity class

Throws:
HibernateException
See Also:
ClassMetadata

getClassMetadata

public ClassMetadata getClassMetadata(String entityName)
                               throws HibernateException
Get the ClassMetadata associated with the given entity name

Throws:
HibernateException
Since:
3.0
See Also:
ClassMetadata

getCollectionMetadata

public CollectionMetadata getCollectionMetadata(String roleName)
                                         throws HibernateException
Get the CollectionMetadata associated with the named collection role

Throws:
HibernateException
See Also:
CollectionMetadata

getAllClassMetadata

public Map getAllClassMetadata()
                        throws HibernateException
Get all ClassMetadata as a Map from entityname String to metadata object

Returns:
a map from String an entity name to ClassMetaData
Throws:
HibernateException
Since:
3.0 changed key from Class to String
See Also:
ClassMetadata

getAllCollectionMetadata

public Map getAllCollectionMetadata()
                             throws HibernateException
Get all CollectionMetadata as a Map from role name to metadata object

Returns:
a map from String to CollectionMetadata
Throws:
HibernateException
See Also:
CollectionMetadata

getStatistics

public Statistics getStatistics()
Get the statistics for this session factory


close

public void close()
           throws HibernateException
Destroy this SessionFactory and release all resources (caches, connection pools, etc). It is the responsibility of the application to ensure that there are no open Sessions before calling close().

Throws:
HibernateException

isClosed

public boolean isClosed()
Was this SessionFactory already closed?


evict

public void evict(Class persistentClass)
           throws HibernateException
Evict all entries from the second-level cache. This method occurs outside of any transaction; it performs an immediate "hard" remove, so does not respect any transaction isolation semantics of the usage strategy. Use with care.

Throws:
HibernateException

evict

public void evict(Class persistentClass,
                  Serializable id)
           throws HibernateException
Evict an entry from the second-level cache. This method occurs outside of any transaction; it performs an immediate "hard" remove, so does not respect any transaction isolation semantics of the usage strategy. Use with care.

Throws:
HibernateException

evictEntity

public void evictEntity(String entityName)
                 throws HibernateException
Evict all entries from the second-level cache. This method occurs outside of any transaction; it performs an immediate "hard" remove, so does not respect any transaction isolation semantics of the usage strategy. Use with care.

Throws:
HibernateException

evictEntity

public void evictEntity(String entityName,
                        Serializable id)
                 throws HibernateException
Evict an entry from the second-level cache. This method occurs outside of any transaction; it performs an immediate "hard" remove, so does not respect any transaction isolation semantics of the usage strategy. Use with care.

Throws:
HibernateException

evictCollection

public void evictCollection(String roleName)
                     throws HibernateException
Evict all entries from the second-level cache. This method occurs outside of any transaction; it performs an immediate "hard" remove, so does not respect any transaction isolation semantics of the usage strategy. Use with care.

Throws:
HibernateException

evictCollection

public void evictCollection(String roleName,
                            Serializable id)
                     throws HibernateException
Evict an entry from the second-level cache. This method occurs outside of any transaction; it performs an immediate "hard" remove, so does not respect any transaction isolation semantics of the usage strategy. Use with care.

Throws:
HibernateException

evictQueries

public void evictQueries()
                  throws HibernateException
Evict any query result sets cached in the default query cache region.

Throws:
HibernateException

evictQueries

public void evictQueries(String cacheRegion)
                  throws HibernateException
Evict any query result sets cached in the named query cache region.

Throws:
HibernateException