English 中文(简体)
是否比使用TransactionSynchronizationManager(S.isActual TransactionActive())更能发现银春季交易是否活跃?
原标题:Is there a better way of detecting if a Spring DB transaction is active than using TransactionSynchronizationManager.isActualTransactionActive()?

我有一些遗产法典,我现在试图在春天重新使用。 在其他法典中,该法典根深蒂固,因此,重新设计并不可行,而且在许多情形下,只有其中一些在春季。 我想做的是,如果开始交易,就使用春季交易;否则,继续使用现有的(合法) d断联系机制。 我们的第一个想法是,把我们的遗产类别变成一个灯塔,并使用一个注入的<条码>TransactionPlatformManager,但这似乎没有任何与我们的情况相适应的方法。 一些研究显示,春季有一个称为<代码>的班级。 TransactionSynchronizationManager, 固定方法isActual Transactionive(。 我的测试表明,如果春季交易活跃的话,这种方法是一种可靠的检测方法:

  • When called via Spring service without the @Transactional annotation, it returns false
  • When called via Spring service with @Transactional, it returns true
  • In my legacy method called the existing way, it returns false

我的问题是: 如果交易活跃,是否有更好的发现方法?

最佳回答

No better way than the TransactionSynchronizationManager.isActualTransactionActive(). It is the utility method used by spring to handle the transactions. Although it is not advisable to use it within your code, for some specific cases you should - that s why it s public.

另一种方式可能是利用实体经理/会议/联系,并在有现有交易的情况下加以核对,但我倾向于同步管理。

问题回答

暂无回答




相关问题
array dependency injection in spring?

is there a way to use dependency injection to inject all available implementations of a specific interface in spring? This is kind of the same thing as asked here for .NET. Though my aim is to use @...

Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Grails Packaging and Naming Conventions

Packaging Controllers, Services,etc. i.e. - com.company.controllers - com.company.services Is this a good practice or should be avoided by all means?? Another worth mentioning problem I encountered ...

How can I determine Objects in application context?

I am trying to write a portlet for Liferay (using Tomcat and Spring) and need to use a database via Persistence API/Hibernate. I am using some configuration XMLs (applicationContext.xml, etc.) and ...

How to prevent JPA from rolling back transaction?

Methods invoked: 1. Struts Action 2. Service class method (annotated by @Transactional) 3. Xfire webservice call Everything including struts (DelegatingActionProxy) and transactions is configured ...

热门标签