public class HibernateTransactionManager
extends org.springframework.transaction.support.AbstractPlatformTransactionManager
implements org.springframework.transaction.support.ResourceTransactionManager, org.springframework.beans.factory.InitializingBean
| Constructor and Description |
|---|
HibernateTransactionManager()
Create a new HibernateTransactionManager instance.
|
HibernateTransactionManager(org.hibernate.SessionFactory sessionFactory)
Create a new HibernateTransactionManager instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet() |
protected org.springframework.dao.DataAccessException |
convertHibernateAccessException(org.hibernate.HibernateException ex)
Convert the given HibernateException to an appropriate exception
from the
org.springframework.dao hierarchy. |
protected void |
doBegin(Object transaction,
org.springframework.transaction.TransactionDefinition definition) |
protected void |
doCleanupAfterCompletion(Object transaction) |
protected void |
doCommit(org.springframework.transaction.support.DefaultTransactionStatus status) |
protected Object |
doGetTransaction() |
protected void |
doResume(Object transaction,
Object suspendedResources) |
protected void |
doRollback(org.springframework.transaction.support.DefaultTransactionStatus status) |
protected void |
doSetRollbackOnly(org.springframework.transaction.support.DefaultTransactionStatus status) |
protected Object |
doSuspend(Object transaction) |
protected DataSource |
getDataSource()
Return the JDBC DataSource that this instance manages transactions for.
|
Object |
getResourceFactory() |
org.hibernate.SessionFactory |
getSessionFactory()
Return the SessionFactory that this instance should manage transactions for.
|
protected boolean |
isExistingTransaction(Object transaction) |
protected boolean |
isSameConnectionForEntireSession(org.hibernate.Session session)
Return whether the given Hibernate Session will always hold the same
JDBC Connection.
|
void |
setHibernateManagedSession(boolean hibernateManagedSession)
Set whether to operate on a Hibernate-managed Session instead of a
Spring-managed Session, that is, whether to obtain the Session through
Hibernate's
SessionFactory.getCurrentSession() instead of
SessionFactory.openSession() (with a Spring
TransactionSynchronizationManager check
preceding it). |
void |
setPrepareConnection(boolean prepareConnection)
Set whether to prepare the underlying JDBC Connection of a transactional
Hibernate Session, that is, whether to apply a transaction-specific
isolation level and/or the transaction's read-only flag to the underlying
JDBC Connection.
|
void |
setSessionFactory(org.hibernate.SessionFactory sessionFactory)
Set the SessionFactory that this instance should manage transactions for.
|
commit, determineTimeout, getDefaultTimeout, getTransaction, getTransactionSynchronization, invokeAfterCompletion, isFailEarlyOnGlobalRollbackOnly, isGlobalRollbackOnParticipationFailure, isNestedTransactionAllowed, isRollbackOnCommitFailure, isValidateExistingTransaction, newTransactionStatus, prepareForCommit, prepareSynchronization, prepareTransactionStatus, registerAfterCompletionWithExistingTransaction, resume, rollback, setDefaultTimeout, setFailEarlyOnGlobalRollbackOnly, setGlobalRollbackOnParticipationFailure, setNestedTransactionAllowed, setRollbackOnCommitFailure, setTransactionSynchronization, setTransactionSynchronizationName, setValidateExistingTransaction, shouldCommitOnGlobalRollbackOnly, suspend, triggerBeforeCommit, triggerBeforeCompletion, useSavepointForNestedTransactionpublic HibernateTransactionManager()
public HibernateTransactionManager(org.hibernate.SessionFactory sessionFactory)
sessionFactory - SessionFactory to manage transactions forpublic void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
public org.hibernate.SessionFactory getSessionFactory()
protected DataSource getDataSource()
public void setPrepareConnection(boolean prepareConnection)
Default is "true". If you turn this flag off, the transaction manager will not support
per-transaction isolation levels anymore. It will not call
Connection.setReadOnly(true) for read-only transactions anymore either. If this
flag is turned off, no cleanup of a JDBC Connection is required after a transaction, since no
Connection settings will get modified.
public void setHibernateManagedSession(boolean hibernateManagedSession)
SessionFactory.getCurrentSession() instead of
SessionFactory.openSession() (with a Spring
TransactionSynchronizationManager check
preceding it).
Default is "false", i.e. using a Spring-managed Session: taking the current thread-bound Session if available (e.g. in an Open-Session-in-View scenario), creating a new Session for the current transaction otherwise.
Switch this flag to "true" in order to enforce use of a Hibernate-managed Session. Note that
this requires SessionFactory.getCurrentSession() to always return a
proper Session when called for a Spring-managed transaction; transaction begin will fail if the
getCurrentSession() call fails.
This mode will typically be used in combination with a custom Hibernate
org.hibernate.context.CurrentSessionContext implementation that stores Sessions in a
place other than Spring's TransactionSynchronizationManager. It may also be used in combination
with Spring's Open-Session-in-View support (using Spring's default
BeangleSessionContext), in which case it subtly differs from the Spring-managed Session
mode: The pre-bound Session will not receive a clear() call (on rollback)
or a disconnect() call (on transaction completion) in such a scenario; this is
rather left up to a custom CurrentSessionContext implementation (if desired).
public void afterPropertiesSet()
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanpublic Object getResourceFactory()
getResourceFactory in interface org.springframework.transaction.support.ResourceTransactionManagerprotected Object doGetTransaction()
doGetTransaction in class org.springframework.transaction.support.AbstractPlatformTransactionManagerprotected boolean isExistingTransaction(Object transaction)
isExistingTransaction in class org.springframework.transaction.support.AbstractPlatformTransactionManagerprotected void doBegin(Object transaction, org.springframework.transaction.TransactionDefinition definition)
doBegin in class org.springframework.transaction.support.AbstractPlatformTransactionManagerprotected Object doSuspend(Object transaction)
doSuspend in class org.springframework.transaction.support.AbstractPlatformTransactionManagerprotected void doResume(Object transaction, Object suspendedResources)
doResume in class org.springframework.transaction.support.AbstractPlatformTransactionManagerprotected void doCommit(org.springframework.transaction.support.DefaultTransactionStatus status)
doCommit in class org.springframework.transaction.support.AbstractPlatformTransactionManagerprotected void doRollback(org.springframework.transaction.support.DefaultTransactionStatus status)
doRollback in class org.springframework.transaction.support.AbstractPlatformTransactionManagerprotected void doSetRollbackOnly(org.springframework.transaction.support.DefaultTransactionStatus status)
doSetRollbackOnly in class org.springframework.transaction.support.AbstractPlatformTransactionManagerprotected void doCleanupAfterCompletion(Object transaction)
doCleanupAfterCompletion in class org.springframework.transaction.support.AbstractPlatformTransactionManagerprotected boolean isSameConnectionForEntireSession(org.hibernate.Session session)
Default implementation checks the Session's connection release mode to be "on_close".
Unfortunately, this requires casting to SessionImpl, as of Hibernate 3.1. If that cast doesn't
work, we'll simply assume we're safe and return true.
session - the Hibernate Session to checkorg.hibernate.impl.SessionImpl#getConnectionReleaseMode(),
ConnectionReleaseMode.ON_CLOSEprotected org.springframework.dao.DataAccessException convertHibernateAccessException(org.hibernate.HibernateException ex)
org.springframework.dao hierarchy.
Will automatically apply a specified SQLExceptionTranslator to a Hibernate JDBCException, else rely on Hibernate's default translation.
ex - HibernateException that occuredCopyright © 2005–2016 The Beangle Software Group. All rights reserved.