Art*_*Art 2 spring hibernate transactions
我在 Spring 中使用 Hibernate,相关配置:
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="openSessionInViewInterceptor" class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
<property name="sessionFactory"><ref bean="sessionFactory" /></property>
</bean>
<tx:annotation-driven />
<aop:aspectj-autoproxy />
Run Code Online (Sandbox Code Playgroud)
想一想...
一些代码想要Connection
从DataSource
. 可能是为了启动一个事务并运行一些 SQL 查询
AbstractRoutingDataSource
执行determineCurrentLookupKey()
以便DataSource
从一组可用的中找到合适的
查找键用于获取当前 DataSource
. AbstractRoutingDataSource
从该数据源返回 JDBC 连接。
连接被返回,AbstractRoutingDataSource
就好像它是一个正常的来源。
现在你问为什么determineCurrentLookupKey()
不在一个事务中运行?首先 Spring 必须转到点 1. 以获取启动事务所需的一些数据库连接。看下一点。看到问题了吗?对我来说就像无限递归。
简单地说 -determineCurrentLookupKey()
不能在事务中运行,因为事务需要一个连接,而该方法的目的是确定DataSource
使用哪个来获取连接。另见:鸡或蛋。
同样,工程师也无法使用计算机来设计第一台计算机。
归档时间: |
|
查看次数: |
4124 次 |
最近记录: |