spring-framework / org.springframework.orm.hibernate5

Package org.springframework.orm.hibernate5

Types

HibernateCallback

interface HibernateCallback<T : Any>

Callback interface for Hibernate code. To be used with HibernateTemplate's execution methods, often as anonymous classes within a method implementation. A typical implementation will call Session.load/find/update to perform some operations on persistent objects.

HibernateTransactionManager

open class HibernateTransactionManager : AbstractPlatformTransactionManager, ResourceTransactionManager, BeanFactoryAware, InitializingBean

org.springframework.transaction.PlatformTransactionManager implementation for a single Hibernate SessionFactory. Binds a Hibernate Session from the specified factory to the thread, potentially allowing for one thread-bound Session per factory. SessionFactory.getCurrentSession() is required for Hibernate access code that needs to support this transaction handling mechanism, with the SessionFactory being configured with SpringSessionContext.

Supports custom isolation levels, and timeouts that get applied as Hibernate transaction timeouts.

This transaction manager is appropriate for applications that use a single Hibernate SessionFactory for transactional data access, but it also supports direct DataSource access within a transaction (i.e. plain JDBC code working with the same DataSource). This allows for mixing services which access Hibernate and services which use plain JDBC (without being aware of Hibernate)! Application code needs to stick to the same simple Connection lookup pattern as with org.springframework.jdbc.datasource.DataSourceTransactionManager (i.e. org.springframework.jdbc.datasource.DataSourceUtils#getConnection or going through a org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy).

Note: To be able to register a DataSource's Connection for plain JDBC code, this instance needs to be aware of the DataSource (#setDataSource). The given DataSource should obviously match the one used by the given SessionFactory.

JTA (usually through org.springframework.transaction.jta.JtaTransactionManager) is necessary for accessing multiple transactional resources within the same transaction. The DataSource that Hibernate uses needs to be JTA-enabled in such a scenario (see container setup).

This transaction manager supports nested transactions via JDBC 3.0 Savepoints. The #setNestedTransactionAllowed "nestedTransactionAllowed"} flag defaults to "false", though, as nested transactions will just apply to the JDBC Connection, not to the Hibernate Session and its cached entity objects and related context. You can manually set the flag to "true" if you want to use nested transactions for JDBC access code which participates in Hibernate transactions (provided that your JDBC driver supports Savepoints). Note that Hibernate itself does not support nested transactions! Hence, do not expect Hibernate access code to semantically participate in a nested transaction.

LocalSessionFactoryBuilder

open class LocalSessionFactoryBuilder : Configuration

A Spring-provided extension of the standard Hibernate Configuration class, adding SpringSessionContext as a default and providing convenient ways to specify a DataSource and an application class loader.

This is designed for programmatic use, e.g. in @Bean factory methods. Consider using LocalSessionFactoryBean for XML bean definition files.

Compatible with Hibernate 5.0/5.1 as well as 5.2, as of Spring 4.3.

SessionHolder

open class SessionHolder : ResourceHolderSupport

Session holder, wrapping a Hibernate Session and a Hibernate Transaction. HibernateTransactionManager binds instances of this class to the thread, for a given SessionFactory.

Note: This is an SPI class, not intended to be used by applications.

SpringFlushSynchronization

open class SpringFlushSynchronization : TransactionSynchronizationAdapter

Simple synchronization adapter that propagates a flush() call to the underlying Hibernate Session. Used in combination with JTA.

SpringJtaSessionContext

open class SpringJtaSessionContext : JTASessionContext

Spring-specific subclass of Hibernate's JTASessionContext, setting FlushMode.MANUAL for read-only transactions.

SpringSessionContext

open class SpringSessionContext : CurrentSessionContext

Implementation of Hibernate 3.1's CurrentSessionContext interface that delegates to Spring's SessionFactoryUtils for providing a Spring-managed current Session.

This CurrentSessionContext implementation can also be specified in custom SessionFactory setup through the "hibernate.current_session_context_class" property, with the fully qualified name of this class as value.

SpringSessionSynchronization

open class SpringSessionSynchronization : TransactionSynchronization, Ordered

Callback for resource cleanup at the end of a Spring-managed transaction for a pre-bound Hibernate Session.

Exceptions

HibernateJdbcException

open class HibernateJdbcException : UncategorizedDataAccessException

Hibernate-specific subclass of UncategorizedDataAccessException, for JDBC exceptions that Hibernate wrapped.

HibernateObjectRetrievalFailureException

open class HibernateObjectRetrievalFailureException : ObjectRetrievalFailureException

Hibernate-specific subclass of ObjectRetrievalFailureException. Converts Hibernate's UnresolvableObjectException and WrongClassException.

HibernateOptimisticLockingFailureException

open class HibernateOptimisticLockingFailureException : ObjectOptimisticLockingFailureException

Hibernate-specific subclass of ObjectOptimisticLockingFailureException. Converts Hibernate's StaleObjectStateException, StaleStateException and OptimisticEntityLockException.

HibernateQueryException

open class HibernateQueryException : InvalidDataAccessResourceUsageException

Hibernate-specific subclass of InvalidDataAccessResourceUsageException, thrown on invalid HQL query syntax.

HibernateSystemException

open class HibernateSystemException : UncategorizedDataAccessException

Hibernate-specific subclass of UncategorizedDataAccessException, for Hibernate system errors that do not match any concrete org.springframework.dao exceptions.