71

What is the difference between JTA, JPA and plain JDBC in terms of Hibernate?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Aashutosh
  • 839
  • 1
  • 10
  • 8

3 Answers3

88

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:

  • JPA is a standard for Java object-relational mapping - it specifies a set of annotations and an interface -EntityManager to 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.

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

Tiny
  • 27,221
  • 105
  • 339
  • 599
Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • 5
    So JTA is what is responsible for the roll back and commits when using an entity manager ? So JPA is using JTA ? Or is JTA used when you have say 2 database replicas ? Please answer I'm confused – Ced Jun 03 '16 at 01:28
  • `In order for a difference to exist, there should be something in common` - What is this an idea or a fact? – Koray Tugay Nov 25 '17 at 21:48
  • @Ced look at the answer bellow. [link o the answer: https://stackoverflow.com/a/59304566/7729614 ] – Soufiane Roui Oct 28 '20 at 19:26
38
  • JDBC is a Java standard for database connection.
  • JPA isolates the Java developer from the inner workings of JDBC and database operations. Hibernate, EclipseLink, OpenJPA and Data Nucleus are famous JPA implementations.
  • JTA is a standard for transactions, allowing for management of multiple transactions among multiple databases.

JPA utilizes JDBC for database connections and SQL-related operations, and -optionally- utilizes JTA for delegating distributed transaction management details to it.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
ozeray
  • 2,134
  • 2
  • 18
  • 13
10

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.

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.)

Praveesh P
  • 1,399
  • 2
  • 25
  • 42