public abstract class SessionFactoryUtils
extends java.lang.Object
Used internally by HibernateTransactionManager
.
Can also be used directly in application code.
HibernateExceptionTranslator
,
HibernateTransactionManager
Modifier and Type | Field and Description |
---|---|
private static java.lang.reflect.Method |
getFlushMode |
(package private) static Log |
logger |
static int |
SESSION_SYNCHRONIZATION_ORDER
Order value for TransactionSynchronization objects that clean up Hibernate Sessions.
|
Constructor and Description |
---|
SessionFactoryUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
closeSession(Session session)
Perform actual closing of the Hibernate Session,
catching and logging any cleanup exceptions thrown.
|
static DataAccessException |
convertHibernateAccessException(HibernateException ex)
Convert the given HibernateException to an appropriate exception
from the
org.springframework.dao hierarchy. |
(package private) static void |
flush(Session session,
boolean synch)
Trigger a flush on the given Hibernate Session, converting regular
HibernateException instances as well as Hibernate 5.2's
PersistenceException wrappers accordingly. |
static javax.sql.DataSource |
getDataSource(SessionFactory sessionFactory)
Determine the DataSource of the given SessionFactory.
|
(package private) static FlushMode |
getFlushMode(Session session)
Get the native Hibernate FlushMode, adapting between Hibernate 5.0/5.1 and 5.2+.
|
public static final int SESSION_SYNCHRONIZATION_ORDER
DataSourceUtils.CONNECTION_SYNCHRONIZATION_ORDER - 100
to execute Session cleanup before JDBC Connection cleanup, if any.static final Log logger
private static java.lang.reflect.Method getFlushMode
static FlushMode getFlushMode(Session session)
session
- the Hibernate Session to get the flush mode fromnull
)static void flush(Session session, boolean synch) throws DataAccessException
HibernateException
instances as well as Hibernate 5.2's
PersistenceException
wrappers accordingly.session
- the Hibernate Session to flushsynch
- whether this flush is triggered by transaction synchronizationDataAccessException
- in case of flush failurespublic static void closeSession(@Nullable Session session)
session
- the Hibernate Session to close (may be null
)Session#close()
@Nullable public static javax.sql.DataSource getDataSource(SessionFactory sessionFactory)
sessionFactory
- the SessionFactory to checknull
if none foundConnectionProvider
public static DataAccessException convertHibernateAccessException(HibernateException ex)
org.springframework.dao
hierarchy.ex
- HibernateException that occurredHibernateExceptionTranslator.convertHibernateAccessException(HibernateException)
,
HibernateTransactionManager.convertHibernateAccessException(HibernateException)