java 我可以将 Hibernate 与 JTA 一起使用吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28253838/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 13:16:31  来源:igfitidea点击:

Can I use Hibernate with JTA?

javaspringhibernatetransactionsjta

提问by user3528733

If JTA is an API, can I use Hibernate as an implementation of JTA?

如果 JTA 是 API,我可以使用 Hibernate 作为 JTA 的实现吗?

I have an application with Spring and Hibernate and I wonder which framework should be responsible for transactions, Spring or Hibernate?

我有一个包含 Spring 和 Hibernate 的应用程序,我想知道哪个框架应该负责事务,Spring 还是 Hibernate?

回答by Vlad Mihalcea

Hibernate is not an implementation of JTA. Hibernate is a JPA implementation.

Hibernate 不是 JTA 的实现。Hibernate 是一个 JPA 实现。

JTA is an enterprise transaction spec, that's implemented by Java EE providers or stand-along transaction managers (e.g. Bitronix).

JTA 是一种企业事务规范,由 Java EE 提供者或独立事务管理器(例如Bitronix)实现。

Hibernate offers a Transaction API abstraction, because ORM tools employ a transactional write-behindPersistence Context.

Hibernate 提供了事务 API 抽象,因为 ORM 工具采用事务性后写持久化上下文。

Spring offers a transaction management abstraction, which allows you to switch from RESOURCE_LOCAL to JTA transactions with just some trivial configuration changes.

Spring 提供了一个事务管理抽象,它允许您从 RESOURCE_LOCAL 切换到 JTA 事务,只需进行一些微不足道的配置更改。

Spring manages to integrate on top of Hibernate/JPA Transaction API abstraction too.

Spring 也设法集成在 Hibernate/JPA 事务 API 抽象之上。

If you use Spring, then you should take advantage of its transaction management abstraction, and so you don't have to use the Hibernate/JPA Transaction API.

如果您使用 Spring,那么您应该利用其事务管理抽象,因此您不必使用 Hibernate/JPA 事务 API。

Because Spring uses AOP, the transaction management is decoupled from your business logic, which would nt be the case if you were using the programmatic Hibernate/JPA Transaction API.

因为 Spring 使用 AOP,事务管理与您的业务逻辑分离,如果您使用编程的 Hibernate/JPA 事务 API,则情况并非如此。