Top Description Fields Constructors Methods
org.springframework.orm.hibernate5

public abstract Class SessionFactoryUtils

extends Object
Class Inheritance
Imports
java.lang.reflect.Method, java.util.Map, javax.sql.DataSource, jakarta.persistence.PersistenceException, org.apache.commons.logging.Log, .LogFactory, org.hibernate.HibernateException, .JDBCException, .NonUniqueObjectException, .NonUniqueResultException, .ObjectDeletedException, .PersistentObjectException, .PessimisticLockException, .PropertyValueException, .QueryException, .QueryTimeoutException, .Session, .SessionFactory, .StaleObjectStateException, .StaleStateException, .TransientObjectException, .UnresolvableObjectException, .WrongClassException, org.hibernate.cfg.Environment, org.hibernate.dialect.lock.OptimisticEntityLockException, .PessimisticEntityLockException, org.hibernate.engine.jdbc.connections.spi.ConnectionProvider, org.hibernate.engine.spi.SessionFactoryImplementor, org.hibernate.exception.ConstraintViolationException, .DataException, .JDBCConnectionException, .LockAcquisitionException, .SQLGrammarException, org.hibernate.service.UnknownServiceException, org.springframework.dao.CannotAcquireLockException, .DataAccessException, .DataAccessResourceFailureException, .DataIntegrityViolationException, .DuplicateKeyException, .IncorrectResultSizeDataAccessException, .InvalidDataAccessApiUsageException, .InvalidDataAccessResourceUsageException, .PessimisticLockingFailureException, org.springframework.jdbc.datasource.DataSourceUtils, org.springframework.lang.Nullable, org.springframework.util.ClassUtils, .ReflectionUtils

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.

Author
Juergen Hoeller
Since
4.2
See Also
HibernateExceptionTranslator, HibernateTransactionManager

Field Summary

Modifier and TypeField and Description
pack-priv static final Log
public static final int
SESSION_SYNCHRONIZATION_ORDER

Order value for TransactionSynchronization objects that clean up Hibernate Sessions.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static void
closeSession(Session
the Hibernate Session to close (may be null)
session
)

Deprecated as a consequence of Session being deprecated.
Perform actual closing of the Hibernate Session, catching and logging any cleanup exceptions thrown.
public static DataAccessException

Returns:

the corresponding DataAccessException instance
convertHibernateAccessException
(HibernateException
the HibernateException that occurred
ex
)

Convert the given HibernateException to an appropriate exception from the org.springframework.dao hierarchy.

pack-priv static void
flush(Session
the Hibernate Session to flush
session
,
boolean
whether this flush is triggered by transaction synchronization
synch
)

Deprecated as a consequence of Session being deprecated.
Trigger a flush on the given Hibernate Session, converting regular HibernateException instances as well as Hibernate 5.2's PersistenceException wrappers accordingly.
public static DataSource

Returns:

the DataSource, or null if none found
getDataSource
(SessionFactory
the SessionFactory to check
sessionFactory
)

Deprecated as a consequence of SessionFactory being deprecated.
Determine the DataSource of the given SessionFactory.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

loggerback to summary
pack-priv static final Log logger
SESSION_SYNCHRONIZATION_ORDERback to summary
public static final int SESSION_SYNCHRONIZATION_ORDER

Order value for TransactionSynchronization objects that clean up Hibernate Sessions. Returns DataSourceUtils.CONNECTION_SYNCHRONIZATION_ORDER - 100 to execute Session cleanup before JDBC Connection cleanup, if any.

See Also
DataSourceUtils#CONNECTION_SYNCHRONIZATION_ORDER

Constructor Detail

SessionFactoryUtilsback to summary
public SessionFactoryUtils()

Method Detail

closeSessionback to summary
public static void closeSession(Session session)

Deprecated

as a consequence of Session being deprecated. See corresponding docs for further information.

Perform actual closing of the Hibernate Session, catching and logging any cleanup exceptions thrown.

Parameters
session:Session

the Hibernate Session to close (may be null)

See Also
Session#close()
convertHibernateAccessExceptionback to summary
public static DataAccessException convertHibernateAccessException(HibernateException ex)

Convert the given HibernateException to an appropriate exception from the org.springframework.dao hierarchy.

Parameters
ex:HibernateException

the HibernateException that occurred

Returns:DataAccessException

the corresponding DataAccessException instance

See Also
HibernateExceptionTranslator#convertHibernateAccessException, HibernateTransactionManager#convertHibernateAccessException
flushback to summary
pack-priv static void flush(Session session, boolean synch) throws DataAccessException

Deprecated

as a consequence of Session being deprecated. See corresponding docs for further information.

Trigger a flush on the given Hibernate Session, converting regular HibernateException instances as well as Hibernate 5.2's PersistenceException wrappers accordingly.

Parameters
session:Session

the Hibernate Session to flush

synch:boolean

whether this flush is triggered by transaction synchronization

Exceptions
DataAccessException:
in case of flush failures
Since
4.3.2
getDataSourceback to summary
public static DataSource getDataSource(SessionFactory sessionFactory)

Deprecated

as a consequence of SessionFactory being deprecated. See corresponding docs for further information.

Determine the DataSource of the given SessionFactory.

Parameters
sessionFactory:SessionFactory

the SessionFactory to check

Returns:DataSource

the DataSource, or null if none found

Annotations
@Nullable
See Also
ConnectionProvider