类 HibernateTransactionManager
- java.lang.Object
-
- org.springframework.transaction.support.AbstractPlatformTransactionManager
-
- org.beangle.orm.hibernate.HibernateTransactionManager
-
- 所有已实现的接口:
Serializable,org.springframework.beans.factory.InitializingBean,org.springframework.transaction.PlatformTransactionManager,org.springframework.transaction.support.ResourceTransactionManager
public class HibernateTransactionManager extends org.springframework.transaction.support.AbstractPlatformTransactionManager implements org.springframework.transaction.support.ResourceTransactionManager, org.springframework.beans.factory.InitializingBeanSimplify HibernateTransactionManager in spring-orm bundle. Just add SessionUtils.isEnableThreadBinding() support in doGetTranscation- 版本:
- $Id: HibernateTransactionManager.java Feb 28, 2012 10:32:50 PM chaostone $
- 作者:
- chaostone
- 另请参阅:
- 序列化表格
-
-
构造器概要
构造器 构造器 说明 HibernateTransactionManager()Create a new HibernateTransactionManager instance.HibernateTransactionManager(org.hibernate.SessionFactory sessionFactory)Create a new HibernateTransactionManager instance.
-
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 voidafterPropertiesSet()protected org.springframework.dao.DataAccessExceptionconvertHibernateAccessException(org.hibernate.HibernateException ex)Convert the given HibernateException to an appropriate exception from theorg.springframework.daohierarchy.protected voiddoBegin(Object transaction, org.springframework.transaction.TransactionDefinition definition)protected voiddoCleanupAfterCompletion(Object transaction)protected voiddoCommit(org.springframework.transaction.support.DefaultTransactionStatus status)protected ObjectdoGetTransaction()protected voiddoResume(Object transaction, Object suspendedResources)protected voiddoRollback(org.springframework.transaction.support.DefaultTransactionStatus status)protected voiddoSetRollbackOnly(org.springframework.transaction.support.DefaultTransactionStatus status)protected ObjectdoSuspend(Object transaction)protected DataSourcegetDataSource()Return the JDBC DataSource that this instance manages transactions for.ObjectgetResourceFactory()org.hibernate.SessionFactorygetSessionFactory()Return the SessionFactory that this instance should manage transactions for.protected booleanisExistingTransaction(Object transaction)protected booleanisSameConnectionForEntireSession(org.hibernate.Session session)Return whether the given Hibernate Session will always hold the same JDBC Connection.voidsetHibernateManagedSession(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'sSessionFactory.getCurrentSession()instead ofSessionFactory.openSession()(with a SpringTransactionSynchronizationManagercheck preceding it).voidsetPrepareConnection(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.voidsetSessionFactory(org.hibernate.SessionFactory sessionFactory)Set the SessionFactory that this instance should manage transactions for.-
从类继承的方法 org.springframework.transaction.support.AbstractPlatformTransactionManager
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, useSavepointForNestedTransaction
-
-
-
-
构造器详细资料
-
HibernateTransactionManager
public HibernateTransactionManager()
Create a new HibernateTransactionManager instance. A SessionFactory has to be set to be able to use it.
-
HibernateTransactionManager
public HibernateTransactionManager(org.hibernate.SessionFactory sessionFactory)
Create a new HibernateTransactionManager instance.- 参数:
sessionFactory- SessionFactory to manage transactions for
-
-
方法详细资料
-
setSessionFactory
public void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
Set the SessionFactory that this instance should manage transactions for.
-
getSessionFactory
public org.hibernate.SessionFactory getSessionFactory()
Return the SessionFactory that this instance should manage transactions for.
-
getDataSource
protected DataSource getDataSource()
Return the JDBC DataSource that this instance manages transactions for.
-
setPrepareConnection
public 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.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.
-
setHibernateManagedSession
public 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'sSessionFactory.getCurrentSession()instead ofSessionFactory.openSession()(with a SpringTransactionSynchronizationManagercheck 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 thegetCurrentSession()call fails.This mode will typically be used in combination with a custom Hibernate
org.hibernate.context.CurrentSessionContextimplementation 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 defaultBeangleSessionContext), in which case it subtly differs from the Spring-managed Session mode: The pre-bound Session will not receive aclear()call (on rollback) or adisconnect()call (on transaction completion) in such a scenario; this is rather left up to a custom CurrentSessionContext implementation (if desired).
-
afterPropertiesSet
public void afterPropertiesSet()
- 指定者:
afterPropertiesSet在接口中org.springframework.beans.factory.InitializingBean
-
getResourceFactory
public Object getResourceFactory()
- 指定者:
getResourceFactory在接口中org.springframework.transaction.support.ResourceTransactionManager
-
doGetTransaction
protected Object doGetTransaction()
- 指定者:
doGetTransaction在类中org.springframework.transaction.support.AbstractPlatformTransactionManager
-
isExistingTransaction
protected boolean isExistingTransaction(Object transaction)
- 覆盖:
isExistingTransaction在类中org.springframework.transaction.support.AbstractPlatformTransactionManager
-
doBegin
protected void doBegin(Object transaction, org.springframework.transaction.TransactionDefinition definition)
- 指定者:
doBegin在类中org.springframework.transaction.support.AbstractPlatformTransactionManager
-
doSuspend
protected Object doSuspend(Object transaction)
- 覆盖:
doSuspend在类中org.springframework.transaction.support.AbstractPlatformTransactionManager
-
doResume
protected void doResume(Object transaction, Object suspendedResources)
- 覆盖:
doResume在类中org.springframework.transaction.support.AbstractPlatformTransactionManager
-
doCommit
protected void doCommit(org.springframework.transaction.support.DefaultTransactionStatus status)
- 指定者:
doCommit在类中org.springframework.transaction.support.AbstractPlatformTransactionManager
-
doRollback
protected void doRollback(org.springframework.transaction.support.DefaultTransactionStatus status)
- 指定者:
doRollback在类中org.springframework.transaction.support.AbstractPlatformTransactionManager
-
doSetRollbackOnly
protected void doSetRollbackOnly(org.springframework.transaction.support.DefaultTransactionStatus status)
- 覆盖:
doSetRollbackOnly在类中org.springframework.transaction.support.AbstractPlatformTransactionManager
-
doCleanupAfterCompletion
protected void doCleanupAfterCompletion(Object transaction)
- 覆盖:
doCleanupAfterCompletion在类中org.springframework.transaction.support.AbstractPlatformTransactionManager
-
isSameConnectionForEntireSession
protected boolean isSameConnectionForEntireSession(org.hibernate.Session session)
Return whether the given Hibernate Session will always hold the same JDBC Connection. This is used to check whether the transaction manager can safely prepare and clean up the JDBC Connection used for a transaction.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 check- 另请参阅:
org.hibernate.impl.SessionImpl#getConnectionReleaseMode(),ConnectionReleaseMode.ON_CLOSE
-
convertHibernateAccessException
protected org.springframework.dao.DataAccessException convertHibernateAccessException(org.hibernate.HibernateException ex)
Convert the given HibernateException to an appropriate exception from theorg.springframework.daohierarchy.Will automatically apply a specified SQLExceptionTranslator to a Hibernate JDBCException, else rely on Hibernate's default translation.
- 参数:
ex- HibernateException that occured- 返回:
- a corresponding DataAccessException
-
-