SessionFactoryUtils (Spring Framework 3.2.1.RELEASE API)
Date: 2013-01-24

org.springframework.orm.hibernate4

## Class SessionFactoryUtils

- java.lang.Object
- - org.springframework.orm.hibernate4.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:
    3.1
  Author:
    Juergen Hoeller
  See Also:
    `HibernateExceptionTranslator`, `HibernateTransactionManager`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `SESSION_SYNCHRONIZATION_ORDER` Order value for TransactionSynchronization objects that clean up Hibernate Sessions.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SessionFactoryUtils()`

  - ### Method Summary

    Methods
    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.
    `static DataSource` | `getDataSource(SessionFactory sessionFactory)` Determine the DataSource of the given SessionFactory.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### SESSION_SYNCHRONIZATION_ORDER

          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`, Constant Field Values

  - ### Constructor Detail

    - #### SessionFactoryUtils

          public SessionFactoryUtils()

  - ### Method Detail

    - #### getDataSource

          public static DataSource getDataSource(SessionFactory sessionFactory)

      Determine the DataSource of the given SessionFactory.
      Parameters:
        `sessionFactory` - the SessionFactory to check
      Returns:
        the DataSource, or `null` if none found
      See Also:
        `SessionFactoryImplementor.getConnectionProvider()`

    - #### 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 be `null`)
      See Also:
        `Session.close()`

    - #### convertHibernateAccessException

          public static DataAccessException convertHibernateAccessException(HibernateException ex)

      Convert the given HibernateException to an appropriate exception from the `org.springframework.dao` hierarchy.
      Parameters:
        `ex` - HibernateException that occured
      Returns:
        the corresponding DataAccessException instance
      See Also:
        `HibernateExceptionTranslator.convertHibernateAccessException(org.hibernate.HibernateException)`, `HibernateTransactionManager.convertHibernateAccessException(org.hibernate.HibernateException)`