Java Hibernate 中 JTA、JPA 和普通 JDBC 的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3903477/
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-08-14 06:34:44  来源:igfitidea点击:

Difference between JTA, JPA and Plain JDBC in hibernate

javahibernatejpajdbcjta

提问by Aashutosh

What is the difference between JTA, JPAand Plain JDBCin terms of Hibernate?

是什么区别JTAJPAPlain JDBCHibernate中的条款?

回答by Bozho

In order for a difference to exist, there should be something in common, and apart from being database-related (although JTA is not only that), they have nothing more in common:

为了存在差异,应该有一些共同点,除了与数据库相关(虽然JTA不仅如此)之外,它们没有更多的共同点:

  • JPA is a standard for Java object-relational mapping - it specifies a set of annotations and an interface -EntityManagerto perform persistence operations with the mapped objects. Hibernate implements the JPA standard

  • plain JDBC is a technology for accessing databases. It is what Hibernate actually uses to perform the database operations, "under the hood". It uses JDBC to send queries to the database.

  • JTAis a transaction API, and it is optional in Hibernate. It handles (logically) the transaction behaviour.

  • JPA 是 Java 对象关系映射的标准——它指定了一组注解和一个接口——EntityManager以对映射对象执行持久化操作。Hibernate 实现了 JPA 标准

  • 普通 JDBC 是一种访问数据库的技术。它实际上是 Hibernate 用于执行数据库操作的“幕后”。它使用 JDBC 向数据库发送查询。

  • JTA是一个事务 API,它在 Hibernate 中是可选的。它处理(逻辑上)事务行为。

回答by ozeray

  • JDBCis a Java standard for database connection.
  • JPAisolates the Java developer from the inner workings of JDBC and database operations. Hibernate, EclipseLink, OpenJPA and Data Nucleus are famous JPA implementations.
  • JTAis a standard for transactions, allowing for management of multiple transactions among multiple databases.
  • JDBC是用于数据库连接的 Java 标准。
  • JPA将 Java 开发人员与 JDBC 和数据库操作的内部工作隔离开来。Hibernate、EclipseLink、OpenJPA 和 Data Nucleus 是著名的 JPA 实现。
  • JTA是事务的标准,允许管理多个数据库之间的多个事务。

JPAutilizes JDBCfor database connections and SQL-related operations, and -optionally- utilizes JTAfor delegating distributed transaction management details to it.

JPA利用JDBC数据库连接和SQL相关操作,以及-optionally-利用JTA委派分布式事务管理的细节吧。

回答by Praveesh P

JPA (Java Persistence API) is the Java ORM standard/specification for storing, accessing, and managing Java objects in a relational database. Hibernate is an implementation of the Java Persistence API (JPA) specification.

JPA(Java Persistence API)是用于在关系数据库中存储、访问和管理 Java 对象的 Java ORM 标准/规范。Hibernate 是 Java Persistence API (JPA) 规范的实现。

JTA (Java Transaction API) is the Java standard/specification for distributed transactions. It comes into picture when you have transactions that spans across multiple connections/DBs/resources. Atomikos is an implementation of JTA. (Appservers like IBM Websphere has their own JTA implementations.)

JTA(Java 事务 API)是分布式事务的 Java 标准/规范。当您的事务跨越多个连接/数据库/资源​​时,它就会出现。Atomikos 是 JTA 的一个实现。(像 IBM Websphere 这样的应用服务器有自己的 JTA 实现。)