Spring Data JPA Tutorial
Spring Data JPA API provides JpaTemplate class to integrate spring application with JPA.
JPA (Java Persistent API) is the sun specification for persisting objects in the enterprise application. It is currently used as the replacement for complex entity beans.
The implementation of JPA specification are provided by many vendors such as:
Advantage of Spring JpaTemplate
You don't need to write the before and after code for persisting, updating, deleting or searching object such as creating Persistence instance, creating EntityManagerFactory instance, creating EntityTransaction instance, creating EntityManager instance, commiting EntityTransaction instance and closing EntityManager.
So, it save a lot of code.
In this example, we are going to use hibernate for the implementation of JPA.
Example of Spring and JPA Integration
Let's see the simple steps to integration spring application with JPA:
In this example, we are going to integrate the hibernate application with spring. Let's see the directory structure of jpa example with spring.
It is a simple POJO class.
This mapping file contains all the information of the persistent class.
The generateDdl property will create the table automatically.
The showSql property will show the sql query on console.
Hibernate: insert into account100 (balance, owner, accountnumber) values (?, ?, ?) Hibernate: insert into account100 (balance, owner, accountnumber) values (?, ?, ?) Accounts created