Without further ado, get right to the point.
What is JPA?
The Java Persistence API, in full, can describe the mapping between objects and relational tables through annotations or XML and persist entity objects to a database.
What it offers us:
- ORM mapping data. JPA supports XML and annotations as two forms of data. Data describes the mapping between objects and tables, and the framework persists entity objects to database tables.
- The JPA API is used to manipulate entity objects and perform CRUD operations. The framework does everything for us in the background, freeing developers from tedious JDBC and SQL code.
- Query language, which queries data through an object-oriented rather than database-oriented query language, avoiding tight coupling of the program’s SQL statements.
Hibernate!
Having said that, JPA is really just a specification, which means that JPA just defines interfaces that need to be implemented to work. So you need some kind of implementation underneath, and Hibernate is the ORM framework that implements the JPA interface.
To be clear, JPA is a set of ORM specifications, and Hibernate implements JPA specifications!
What is Spring Data JPA?
Spring Data JPA is a set of framework provided by Spring to simplify JPA development. According to the agreed write Dao layer interface, you can achieve access and operation to the database without writing interface implementation. It also provides many functions in addition to CRUD, such as paging, sorting, complex queries, and so on.
SpringBoot!
Integrating Spring Data JPA with SpringBoot is simple in two steps: Step 1: Import Maven
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
Copy the code
Step 2: Configure JPA information
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost/xxx? useSSL=false&characterEncoding=utf8&serverTimezone=GMT%2B8
username: root
password: 12345
jpa:
database: mysql
show-sql: true
hibernate:
ddl-auto: update
Copy the code