orm
Last updated
Last updated
Basically...
Save to database : Object -> ORM -> Database
Extract from database : Database -> ORM -> Object
JPA is a Java specification for managing relational data in an object-oriented way, enabling the mapping of Java objects to database tables and simplifying database interactions.
It is not an implementation, but a specification that various ORM frameworks, like Hibernate, EclipseLink, and Apache OpenJPA, implement.
Hibernate is an ORM framework that facilitates the mapping of Java objects to database tables and simplifies database interactions in Java applications.
It is an implementation framework that follows the JPA specification ( one of the JPA providers )
Spring Data JPA is a framework that builds on top of JPA (including Hibernate as a potential JPA provider) to make it even easier to work with databases in Spring applications (extra layer of abstraction)
It is not an implementation or JPA provider, it's just an abstraction used to significantly reduce the amount of boilerplate code required to implement data access layers for various persistence stores.
File Structure for Spring Boot application:
StudentController: Concrete class that manages endpoints for frontend / REST API calls
StudentRepository: Fulfils the role of repository (other classes can use it to manipulate database)
Student: POJO Student entity that is used to map to database
StudentService: Interface for StudentServiceImpl
StudentServiceImpl: Service class defines methods that interact with the repository and are invoked by the controller.
As you can see we can easily use Spring Data JPA in Spring / Spring Boot applications by just :
creating a entity POJO class
a repository interface class which extends the JpaRepository interface which enables the repository to use its database CRUD methods.