简体   繁体   English

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

[英]Can I use Hibernate with JTA?

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?

Hibernate is not an implementation of JTA. Hibernate 不是 JTA 的实现。 Hibernate is a JPA implementation. Hibernate 是一个 JPA 实现。

JTA is an enterprise transaction spec, that's implemented by Java EE providers or stand-along transaction managers (eg Bitronix ). JTA 是一种企业事务规范,由 Java EE 提供者或独立事务管理器(例如Bitronix )实现。

Hibernate offers a Transaction API abstraction because ORM tools employ a transactional write-behind Persistence 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 not be the case if you were using the programmatic Hibernate/JPA Transaction API.因为 Spring 使用 AOP,事务管理与您的业务逻辑分离,如果您使用编程的 Hibernate/JPA 事务 API,则情况并非如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM