Difference between JTA, JPA and plain JDBC in hibernate

JavaHibernateJpaJdbcJta

Java Problem Overview


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

Java Solutions


Solution 1 - Java

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.

Solution 2 - Java

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

Solution 3 - Java

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAashutoshView Question on Stackoverflow
Solution 1 - JavaBozhoView Answer on Stackoverflow
Solution 2 - JavaozerayView Answer on Stackoverflow
Solution 3 - JavaPraveesh PView Answer on Stackoverflow