gpt4 book ai didi

spring - 我应该使用哪个事务管理器(JTA 与 JPA)?

转载 作者:IT老高 更新时间:2023-10-28 13:49:31 25 4
gpt4 key购买 nike

我有 spring 4 应用程序。目前我使用 JpatransactionManager。

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

您能告诉我如何选择事务管理器吗?

例如,我应该什么时候使用jta事务管理器,什么时候使用jpa,它们有什么好处和坏处?

我知道我在 Spring 有两种工作方式吗?一是JPA方式,二是Hibernate方式。第一个包括java标准注释和标准api,第二个是hibenrate实现。如果我需要使用 JTA,我必须使用 hibernate 而不是 JPA,不是吗?

最佳答案

如果您想将托管事务委托(delegate)给您的应用程序服务器并处理跨多个资源的复杂事务,您需要使用 JtaTransactionManager,但我相信在大多数情况下不需要它。阅读本文了解更多信息 http://docs.spring.io/spring-framework/docs/4.0.x/spring-framework-reference/html/transaction.html

Do you need an application server for transaction management?

The Spring Framework’s transaction management support changes traditional rules as to when an enterprise Java application requires an application server.

In particular, you do not need an application server simply for declarative transactions through EJBs. In fact, even if your application server has powerful JTA capabilities, you may decide that the Spring Framework’s declarative transactions offer more power and a more productive programming model than EJB CMT.

Typically you need an application server’s JTA capability only if your application needs to handle transactions across multiple resources, which is not a requirement for many applications. Many high-end applications use a single, highly scalable database (such as Oracle RAC) instead. Standalone transaction managers such as Atomikos Transactions and JOTM are other options. Of course, you may need other application server capabilities such as Java Message Service (JMS) and Java EE Connector Architecture (JCA).

The Spring Framework gives you the choice of when to scale your application to a fully loaded application server. Gone are the days when the only alternative to using EJB CMT or JTA was to write code with local transactions such as those on JDBC connections, and face a hefty rework if you need that code to run within global, container-managed transactions. With the Spring Framework, only some of the bean definitions in your configuration file, rather than your code, need to change.

关于spring - 我应该使用哪个事务管理器(JTA 与 JPA)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26482495/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com