|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.orm.hibernate.SessionFactoryUtils
Helper class featuring methods for Hibernate session handling, allowing for reuse of Hibernate Session instances within transactions.
Used internally by HibernateTemplate, HibernateInterceptor, and HibernateTransactionManager. Can also be used directly in application code, e.g. in combination with HibernateInterceptor.
Note: Spring's Hibernate support requires Hibernate 2.1 (as of Spring 1.0).
HibernateTemplate
,
HibernateInterceptor
,
HibernateTransactionManager
,
JtaTransactionManager
Constructor Summary | |
SessionFactoryUtils()
|
Method Summary | |
static void |
applyTransactionTimeout(net.sf.hibernate.Criteria criteria,
net.sf.hibernate.SessionFactory sessionFactory)
Apply the current transaction timeout, if any, to the given Hibernate Criteria object. |
static void |
applyTransactionTimeout(net.sf.hibernate.Query query,
net.sf.hibernate.SessionFactory sessionFactory)
Apply the current transaction timeout, if any, to the given Hibernate Query object. |
static void |
closeSessionIfNecessary(net.sf.hibernate.Session session,
net.sf.hibernate.SessionFactory sessionFactory)
Close the given Session, created via the given factory, if it isn't bound to the thread. |
static DataAccessException |
convertHibernateAccessException(net.sf.hibernate.HibernateException ex)
Convert the given HibernateException to an appropriate exception from the org.springframework.dao hierarchy. |
static net.sf.hibernate.Session |
getSession(net.sf.hibernate.SessionFactory sessionFactory,
boolean allowCreate)
Get a Hibernate Session for the given factory. |
static net.sf.hibernate.Session |
getSession(net.sf.hibernate.SessionFactory sessionFactory,
net.sf.hibernate.Interceptor entityInterceptor,
SQLExceptionTranslator jdbcExceptionTranslator)
Get a Hibernate Session for the given factory. |
static net.sf.hibernate.Session |
getSession(net.sf.hibernate.SessionFactory sessionFactory,
net.sf.hibernate.Interceptor entityInterceptor,
SQLExceptionTranslator jdbcExceptionTranslator,
boolean allowSynchronization)
Get a Hibernate Session for the given factory. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public SessionFactoryUtils()
Method Detail |
public static net.sf.hibernate.Session getSession(net.sf.hibernate.SessionFactory sessionFactory, boolean allowCreate) throws DataAccessResourceFailureException, java.lang.IllegalStateException
This is the getSession method used by typical data access code, in combination with closeSessionIfNecessary called when done with the Session. Note that HibernateTemplate allows to write data access code without caring about such resource handling.
sessionFactory
- Hibernate SessionFactory to create the session withallowCreate
- if a new Session should be created if no thread-bound found
DataAccessResourceFailureException
- if the Session couldn't be created
java.lang.IllegalStateException
- if no thread-bound Session found and allowCreate falsecloseSessionIfNecessary(net.sf.hibernate.Session, net.sf.hibernate.SessionFactory)
,
HibernateTemplate
public static net.sf.hibernate.Session getSession(net.sf.hibernate.SessionFactory sessionFactory, net.sf.hibernate.Interceptor entityInterceptor, SQLExceptionTranslator jdbcExceptionTranslator)
Supports synchronization with JTA transactions via TransactionSynchronizationManager, to allow for proper transactional handling of the JVM-level cache.
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.
sessionFactory
- Hibernate SessionFactory to create the session withentityInterceptor
- Hibernate entity interceptor, or null if nonejdbcExceptionTranslator
- SQLExcepionTranslator to use for flushing the
Session on transaction synchronization (can be null; only used when actually
registering a transaction synchronization)
DataAccessResourceFailureException
- if the Session couldn't be createdLocalSessionFactoryBean.setEntityInterceptor(net.sf.hibernate.Interceptor)
,
TransactionSynchronizationManager
public static net.sf.hibernate.Session getSession(net.sf.hibernate.SessionFactory sessionFactory, net.sf.hibernate.Interceptor entityInterceptor, SQLExceptionTranslator jdbcExceptionTranslator, boolean allowSynchronization) throws DataAccessResourceFailureException
Supports synchronization with JTA transactions via TransactionSynchronizationManager, to allow for proper transactional handling of the JVM-level cache.
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.
sessionFactory
- Hibernate SessionFactory to create the session withentityInterceptor
- Hibernate entity interceptor, or null if nonejdbcExceptionTranslator
- SQLExcepionTranslator to use for flushing the
Session on transaction synchronization (can be null; only used when actually
registering a transaction synchronization)allowSynchronization
- if a new Hibernate Session is supposed to be
registered with transaction synchronization (if synchronization is active).
This will always be true for typical data access code.
DataAccessResourceFailureException
- if the Session couldn't be createdgetSession(SessionFactory, Interceptor, SQLExceptionTranslator)
,
LocalSessionFactoryBean.setEntityInterceptor(net.sf.hibernate.Interceptor)
,
TransactionSynchronizationManager
public static void applyTransactionTimeout(net.sf.hibernate.Query query, net.sf.hibernate.SessionFactory sessionFactory)
query
- the Hibernate Query objectsessionFactory
- Hibernate SessionFactory that the Query was created forpublic static void applyTransactionTimeout(net.sf.hibernate.Criteria criteria, net.sf.hibernate.SessionFactory sessionFactory)
criteria
- the Hibernate Criteria objectsessionFactory
- Hibernate SessionFactory that the Criteria was created forpublic static DataAccessException convertHibernateAccessException(net.sf.hibernate.HibernateException ex)
ex
- HibernateException that occured
HibernateAccessor.convertHibernateAccessException(net.sf.hibernate.HibernateException)
,
HibernateAccessor.convertJdbcAccessException(java.sql.SQLException)
,
HibernateTemplate.execute(org.springframework.orm.hibernate.HibernateCallback)
public static void closeSessionIfNecessary(net.sf.hibernate.Session session, net.sf.hibernate.SessionFactory sessionFactory) throws CleanupFailureDataAccessException
session
- Session to closesessionFactory
- Hibernate SessionFactory that the Session was created with
DataAccessResourceFailureException
- if the Session couldn't be closed
CleanupFailureDataAccessException
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |