π¦ What is Spring Data JPA?
Spring Data JPA is a part of the Spring framework that helps you work with databases easily using Java objects.
It sits on top of JPA (Java Persistence API) and uses Hibernate under the hood to perform operations like save, update, delete, or fetch data from a database.
π§ It removes the need for writing complex SQL queries. You just write method names, and Spring creates the query for you!
π‘ Real-World Analogy
Think of your database as a giant Excel sheet.
Spring Data JPA gives you a simple way to read, write, and update rows in that sheet β using Java code, not SQL.
π οΈ Basic Components
1. Entity β Your table
2. Repository β Your database operations
You get all basic methods like:
save()
findById()
findAll()
-
deleteById()
without writing any SQL.
π Why Use Spring Data JPA?
β
Saves time
β
Reduces boilerplate code
β
Auto-generates queries
β
Works with different databases
β
Integrates easily with Spring Boot
π Summary
Term | Meaning |
---|---|
@Entity |
Marks a class as a database table |
@Id |
Primary key |
JpaRepository |
Interface to interact with DB |
findBy... |
Auto query creation by method name |