What is JPA?

JPA stands for Java Persistence API. JPA uses JDK 5.0 annotations or XML to describe the object-relationship table mapping relationship and persists the entity objects at runtime into the database. 

The above is just a definition of JPA, let’s take a look at another paragraph to better understand what it is:

spring boot jpa

JPA (Java Persistence API) is the Java Persistence Specification officially proposed by Sun. It provides Java developers with an object / relational mapping tool to manage relational data in Java applications.

In this passage it is clearer, there is a keyword “persistence specification” here. We can split it into two parts to read “persistence” and “normative”. 

The so-called persistence is the conversion of program data from transient data(such as data in memory) to persistent data ( save to a database, a disk file …). This personal rough description, look at the professional description, as follows:

Persistence, that is, saving data (such as objects in memory) to a persistent storage device (such as a disk). The main application of persistence is to store objects in memory in a database, or in disk files, XML data files, and so on.

Persistence is a mechanism that transforms program data between persistent and transient states.

JDBC is a persistence mechanism. File IO is also a persistence mechanism.

Well, the description above is very clear, we are talking about “standards”: the so-called norms are intended to indicate the standards stipulated by the text or conventions. Such as ethical standards, technical standards, company management standards.

What is Hibernate?

Hibernate is an open-source object-relational mapping framework. It implements a very lightweight object encapsulation for JDBC. It establishes a mapping relationship between POJOs and database tables. It is a fully automatic ORM framework.

Hibernate can automatically generate SQL statements. Automated execution allows Java programmers to manipulate the database using object programming thinking at will. Hibernate can be used in any situation where JDBC is used. It can be used in Java client programs or in Servlet / JSP web applications. The most revolutionary is that Hibernate can replace CMP in the J2EE architecture of EJB. To complete the important task of data persistence.

In the above description, the core sentence can be “a fully automatic ORM framework”. 

So, what is ORM?

ORM stands for Object Relational Mapping, which is a program technology used to implement data conversion between systems of different system types in an object-oriented programming language. Well, more concepts need to be explored by yourself, here is just a pretense.

What is Spring Data?

Spring Data is an open-source framework for simplifying database access and supporting cloud services. Its main goal is to make database access convenient and fast and support the map-reduce framework and cloud computing data services. 

In addition, it supports data services based on relational databases, such as Oracle RAC, etc. For projects with large amounts of data, Spring Data can be used to simplify project development. Just like the Spring Framework’s support for JDBC and ORM, Spring Data will make data access more convenient.

In the above description, I think the core is “Spring Data is an open-source framework for simplifying database access and supporting cloud services.” 

What is Spring Data JPA?

What Spring Data JPA can do?

It can greatly simplify the writing of JPA and can achieve data access and operations without writing. In addition to CRUD, it also includes some common functions such as paging and sorting.

The first thing we need to know is that Spring Data is an open-source framework. In this framework, Spring Data JPA is just a module in this framework, so the name is Spring.

Data JPA. If you use JPA development alone, you will find this code amount is as annoying as JDBC development, so the appearance of Spring Data JPA is to simplify the writing of JPA, so that you only need to write an interface to inherit a class to implement CRUD operations.

What the relationship of JPA with Hibernate?

JPA is a specification, and Hibernate is an implementation of it.

In addition to Hibernate, there are EclipseLink (formerly toplink), OpenJPA, etc., so one of the benefits of using JPA is that you can change the implementation without having to change too much code.

From the above description, we can just see: JPA defines a specification, Hibernate is one of the implementation methods, so we can say that Hibernate is an implementation method of JPA. 

But it’s a bit inappropriate to say whether to use hibernate or JPA for development. If you answer using JPA, then you can’t do much at all, because you need to use a specific implementation of it, such as Hibernate, EclipseLink, toplink. 

If the answer is to use Hibernate, I still barely say the past, but there is also a shadow of JPA in Hibernate. But don’t cause a misunderstanding here. Hibernate must depend on JPA or something. JPA is now only a subset of Hibernate functions. 

So, when we describe it, others ask you what is used specifically for persistence. We can say that using JPA based on Hibernate implementation or Hibernate JPA, then with spring data, we generally simplify spring data JPA.

And the general default is to use hibernate for implementation, and now there is more information in this area on the Internet, it may be a convention. Of course, if you want others to be clear, you can add it yourself.