| java.lang.Object org.springframework.orm.hibernate3.SessionFactoryUtils
Method Summary | |
public static void | applyTransactionTimeout(Query query, SessionFactory sessionFactory) Apply the current transaction timeout, if any, to the given
Hibernate Query object. | public static void | applyTransactionTimeout(Criteria criteria, SessionFactory sessionFactory) Apply the current transaction timeout, if any, to the given
Hibernate Criteria object. | public static void | closeSession(Session session) Perform actual closing of the Hibernate Session,
catching and logging any cleanup exceptions thrown. | static void | closeSessionOrRegisterDeferredClose(Session session, SessionFactory sessionFactory) Close the given Session or register it for deferred close. | public static DataAccessException | convertHibernateAccessException(HibernateException ex) Convert the given HibernateException to an appropriate exception
from the org.springframework.dao hierarchy. | public static Session | doGetSession(SessionFactory sessionFactory, boolean allowCreate) Get a Hibernate Session for the given SessionFactory. | public static DataSource | getDataSource(SessionFactory sessionFactory) Determine the DataSource of the given SessionFactory. | public static TransactionManager | getJtaTransactionManager(SessionFactory sessionFactory, Session session) Try to retrieve the JTA TransactionManager from the given SessionFactory
and/or Session. | public static Session | getNewSession(SessionFactory sessionFactory) Get a new Hibernate Session from the given SessionFactory.
Will return a new Session even if there already is a pre-bound
Session for the given SessionFactory.
Within a transaction, this method will create a new Session
that shares the transaction's JDBC Connection. | public static Session | getNewSession(SessionFactory sessionFactory, Interceptor entityInterceptor) Get a new Hibernate Session from the given SessionFactory.
Will return a new Session even if there already is a pre-bound
Session for the given SessionFactory.
Within a transaction, this method will create a new Session
that shares the transaction's JDBC Connection. | public static Session | getSession(SessionFactory sessionFactory, boolean allowCreate) Get a Hibernate Session for the given SessionFactory. | public static Session | getSession(SessionFactory sessionFactory, Interceptor entityInterceptor, SQLExceptionTranslator jdbcExceptionTranslator) Get a Hibernate Session for the given SessionFactory. | public static void | initDeferredClose(SessionFactory sessionFactory) Initialize deferred close for the current thread and the given SessionFactory. | public static boolean | isDeferredCloseActive(SessionFactory sessionFactory) Determine whether deferred close is active for the current thread
and the given SessionFactory. | public static boolean | isSessionTransactional(Session session, SessionFactory sessionFactory) Return whether the given Hibernate Session is transactional, that is,
bound to the current thread by Spring's transaction facilities. | public static SQLExceptionTranslator | newJdbcExceptionTranslator(SessionFactory sessionFactory) Create an appropriate SQLExceptionTranslator for the given SessionFactory. | public static void | processDeferredClose(SessionFactory sessionFactory) Process all Hibernate Sessions that have been registered for deferred close
for the given SessionFactory. | public static void | releaseSession(Session session, SessionFactory sessionFactory) Close the given Session, created via the given factory,
if it is not managed externally (i.e. | public static String | toString(Session session) Stringify the given Session for debug logging. |
logger | final static Log logger(Code) | | |
applyTransactionTimeout | public static void applyTransactionTimeout(Query query, SessionFactory sessionFactory)(Code) | | Apply the current transaction timeout, if any, to the given
Hibernate Query object.
Parameters: query - the Hibernate Query object Parameters: sessionFactory - Hibernate SessionFactory that the Query was created for(may be null ) See Also: org.hibernate.Query.setTimeout |
applyTransactionTimeout | public static void applyTransactionTimeout(Criteria criteria, SessionFactory sessionFactory)(Code) | | Apply the current transaction timeout, if any, to the given
Hibernate Criteria object.
Parameters: criteria - the Hibernate Criteria object Parameters: sessionFactory - Hibernate SessionFactory that the Criteria was created for See Also: org.hibernate.Criteria.setTimeout |
closeSession | public static void closeSession(Session session)(Code) | | Perform actual closing of the Hibernate Session,
catching and logging any cleanup exceptions thrown.
Parameters: session - the Hibernate Session to close (may be null ) See Also: org.hibernate.Session.close |
closeSessionOrRegisterDeferredClose | static void closeSessionOrRegisterDeferredClose(Session session, SessionFactory sessionFactory)(Code) | | Close the given Session or register it for deferred close.
Parameters: session - the Hibernate Session to close Parameters: sessionFactory - Hibernate SessionFactory that the Session was created with(may be null ) See Also: SessionFactoryUtils.initDeferredClose See Also: SessionFactoryUtils.processDeferredClose |
doGetSession | public static Session doGetSession(SessionFactory sessionFactory, boolean allowCreate) throws HibernateException, IllegalStateException(Code) | | Get a Hibernate Session for the given SessionFactory. Is aware of and will
return any existing corresponding Session bound to the current thread, for
example when using
HibernateTransactionManager . Will create a new
Session otherwise, if "allowCreate" is true .
Throws the original HibernateException, in contrast to
SessionFactoryUtils.getSession .
Parameters: sessionFactory - Hibernate SessionFactory to create the session with Parameters: allowCreate - whether a non-transactional Session should be createdwhen no transactional Session can be found for the current thread the Hibernate Session throws: HibernateException - if the Session couldn't be created throws: IllegalStateException - if no thread-bound Session found and allowCreate false |
getDataSource | public static DataSource getDataSource(SessionFactory sessionFactory)(Code) | | Determine the DataSource of the given SessionFactory.
Parameters: sessionFactory - the SessionFactory to check the DataSource, or null if none found See Also: org.hibernate.engine.SessionFactoryImplementor.getConnectionProvider See Also: LocalDataSourceConnectionProvider |
getJtaTransactionManager | public static TransactionManager getJtaTransactionManager(SessionFactory sessionFactory, Session session)(Code) | | Try to retrieve the JTA TransactionManager from the given SessionFactory
and/or Session. Check the passed-in SessionFactory for implementing
SessionFactoryImplementor (the usual case), falling back to the
SessionFactory reference that the Session itself carries.
Parameters: sessionFactory - Hibernate SessionFactory Parameters: session - Hibernate Session (can also be null ) the JTA TransactionManager, if any See Also: javax.transaction.TransactionManager See Also: SessionFactoryImplementor.getTransactionManager See Also: Session.getSessionFactory See Also: org.hibernate.impl.SessionFactoryImpl |
getNewSession | public static Session getNewSession(SessionFactory sessionFactory)(Code) | | Get a new Hibernate Session from the given SessionFactory.
Will return a new Session even if there already is a pre-bound
Session for the given SessionFactory.
Within a transaction, this method will create a new Session
that shares the transaction's JDBC Connection. More specifically,
it will use the same JDBC Connection as the pre-bound Hibernate Session.
Parameters: sessionFactory - Hibernate SessionFactory to create the session with the new Session |
getNewSession | public static Session getNewSession(SessionFactory sessionFactory, Interceptor entityInterceptor)(Code) | | Get a new Hibernate Session from the given SessionFactory.
Will return a new Session even if there already is a pre-bound
Session for the given SessionFactory.
Within a transaction, this method will create a new Session
that shares the transaction's JDBC Connection. More specifically,
it will use the same JDBC Connection as the pre-bound Hibernate Session.
Parameters: sessionFactory - Hibernate SessionFactory to create the session with Parameters: entityInterceptor - Hibernate entity interceptor, or null if none the new Session |
getSession | public static Session getSession(SessionFactory sessionFactory, Interceptor entityInterceptor, SQLExceptionTranslator jdbcExceptionTranslator) throws DataAccessResourceFailureException(Code) | | Get a Hibernate Session for the given SessionFactory. Is aware of and will
return any existing corresponding Session bound to the current thread, for
example when using
HibernateTransactionManager . Will always create
a new Session otherwise.
Supports setting a Session-level Hibernate entity interceptor that allows
to inspect and change property values before writing to and reading from the
database. Such an interceptor can also be set at the SessionFactory level
(i.e. on LocalSessionFactoryBean), on HibernateTransactionManager, or on
HibernateInterceptor/HibernateTemplate.
Parameters: sessionFactory - Hibernate SessionFactory to create the session with Parameters: entityInterceptor - Hibernate entity interceptor, or null if none Parameters: jdbcExceptionTranslator - SQLExcepionTranslator to use for flushing theSession on transaction synchronization (may be null ; only usedwhen actually registering a transaction synchronization) the Hibernate Session throws: DataAccessResourceFailureException - if the Session couldn't be created See Also: LocalSessionFactoryBean.setEntityInterceptor See Also: HibernateInterceptor.setEntityInterceptor See Also: HibernateTemplate.setEntityInterceptor |
isDeferredCloseActive | public static boolean isDeferredCloseActive(SessionFactory sessionFactory)(Code) | | Determine whether deferred close is active for the current thread
and the given SessionFactory.
Parameters: sessionFactory - the Hibernate SessionFactory to check whether deferred close is active |
isSessionTransactional | public static boolean isSessionTransactional(Session session, SessionFactory sessionFactory)(Code) | | Return whether the given Hibernate Session is transactional, that is,
bound to the current thread by Spring's transaction facilities.
Parameters: session - the Hibernate Session to check Parameters: sessionFactory - Hibernate SessionFactory that the Session was created with(may be null ) whether the Session is transactional |
releaseSession | public static void releaseSession(Session session, SessionFactory sessionFactory)(Code) | | Close the given Session, created via the given factory,
if it is not managed externally (i.e. not bound to the thread).
Parameters: session - the Hibernate Session to close (may be null ) Parameters: sessionFactory - Hibernate SessionFactory that the Session was created with(may be null ) |
toString | public static String toString(Session session)(Code) | | Stringify the given Session for debug logging.
Returns output equivalent to Object.toString() :
the fully qualified class name + "@" + the identity hash code.
The only reason why this is necessary is because Hibernate3's
Session.toString() implementation is broken (and won't be fixed):
it logs the toString representation of all persistent objects in the Session,
which might lead to ConcurrentModificationExceptions if the persistent objects
in turn refer to the Session (for example, for lazy loading).
Parameters: session - the Hibernate Session to stringify the String representation of the given Session |
|
|