Class SessionFactoryUtils
- java.lang.Object
- org.springframework.orm.hibernate5.SessionFactoryUtils
public abstract class SessionFactoryUtils extends Object
Helper class featuring methods for Hibernate Session handling. Also provides support for exception translation.Used internally by
HibernateTransactionManager. Can also be used directly in application code.- Since:
- 4.2
- Author:
- Juergen Hoeller
- See Also:
HibernateExceptionTranslator,HibernateTransactionManager
Field Summary
Fields Modifier and Type Field Description static intSESSION_SYNCHRONIZATION_ORDEROrder value for TransactionSynchronization objects that clean up Hibernate Sessions.
Constructor Summary
Constructors Constructor Description SessionFactoryUtils()
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcloseSession(Session session)Perform actual closing of the Hibernate Session, catching and logging any cleanup exceptions thrown.static DataAccessExceptionconvertHibernateAccessException(HibernateException ex)Convert the given HibernateException to an appropriate exception from theorg.springframework.daohierarchy.static DataSourcegetDataSource(SessionFactory sessionFactory)Determine the DataSource of the given SessionFactory.
Field Detail
SESSION_SYNCHRONIZATION_ORDER
public static final int SESSION_SYNCHRONIZATION_ORDER
Order value for TransactionSynchronization objects that clean up Hibernate Sessions. ReturnsDataSourceUtils.CONNECTION_SYNCHRONIZATION_ORDER - 100to execute Session cleanup before JDBC Connection cleanup, if any.
Constructor Detail
SessionFactoryUtils
public SessionFactoryUtils()
Method Detail
closeSession
public static void closeSession(Session session)
Perform actual closing of the Hibernate Session, catching and logging any cleanup exceptions thrown.- Parameters:
session- the Hibernate Session to close (may benull)- See Also:
Session.close()
getDataSource
public static DataSource getDataSource(SessionFactory sessionFactory)
Determine the DataSource of the given SessionFactory.- Parameters:
sessionFactory- the SessionFactory to check- Returns:
- the DataSource, or
nullif none found - See Also:
ConnectionProvider
convertHibernateAccessException
public static DataAccessException convertHibernateAccessException(HibernateException ex)
Convert the given HibernateException to an appropriate exception from theorg.springframework.daohierarchy.- Parameters:
ex- HibernateException that occurred- Returns:
- the corresponding DataAccessException instance
- See Also:
HibernateExceptionTranslator.convertHibernateAccessException(org.hibernate.HibernateException),HibernateTransactionManager.convertHibernateAccessException(org.hibernate.HibernateException)