最近开发中,遇到了这样一个问题。
1.系统中,事务是有spring管理的。
2.系统中,即用到了JDBC,又用到了Hibernate。
3.spring管理了jdbc事务,也管理了Hibernate事务。
如上3点所述,存在这样的情况:
配置了jdbc事务的service,注入了配置了hibernate事务的service。这时,执行的时候,系统就会抛出异常:
[color=red]org.springframework.transaction.IllegalTransactionStateException: Pre-bound JDBC connection found - HibernateTransactionManager does not support running within DataSourceTransactionManager if told to manage the DataSource itself. It is recommended to use a single HibernateTransactionManager for all transactions on a single DataSource, no matter whether Hibernate or JDBC access.[/color]
但是,由配置了hibernate事务的service,注入了配置了jdbc事务的service。就能正常运行。
不知道大家有没有遇到过类似的问题。一起讨论一下。
1.系统中,事务是有spring管理的。
2.系统中,即用到了JDBC,又用到了Hibernate。
3.spring管理了jdbc事务,也管理了Hibernate事务。
如上3点所述,存在这样的情况:
配置了jdbc事务的service,注入了配置了hibernate事务的service。这时,执行的时候,系统就会抛出异常:
[color=red]org.springframework.transaction.IllegalTransactionStateException: Pre-bound JDBC connection found - HibernateTransactionManager does not support running within DataSourceTransactionManager if told to manage the DataSource itself. It is recommended to use a single HibernateTransactionManager for all transactions on a single DataSource, no matter whether Hibernate or JDBC access.[/color]
但是,由配置了hibernate事务的service,注入了配置了jdbc事务的service。就能正常运行。
不知道大家有没有遇到过类似的问题。一起讨论一下。