Skip to content

Latest commit

 

History

History
38 lines (29 loc) · 1.91 KB

File metadata and controls

38 lines (29 loc) · 1.91 KB

ORM - Object Relational Mapping

  1. ORM - is a technique used to map Java objects to database tables. All the operation that we do with java object will be performed in database.
    1. It allows developer to work with databases using OOP concept, making it easier to interact with relational databases.
  2. ORM frameworks - like hibernate.
  3. How does it work ?
    1. Consider a Java class User and a database table users.
    2. ORM framework like Hibernate can map the fields in the User class to columns in the users table, making it easier to insert, update, retrieve and delete the record.

JPA (Java Persistence API)

  1. JPA is a way to achieve ORM, it includes interfaces and annotations that you use in Java classes, requires a persistence provider(ORM TOOL) for implementation.
  2. To use JPA, you need a persistence provider. Ex of JPA persistence providers includes - Hibernate, EclipseLink and OpenJPA. These providers implement the JPA interface and provider the underlying functionality to interact with databases.
        Spring JPA --> JPA --> Hibernate(implementation of JPA) --> Database
    
  3. JPA is primarily designed for working with relational databases, where data is stored in table with predefined schema.
    1. MongoDb, on other hand is NoSQL database, which are schema less/flexible schema.
    2. Hence JPA is not used with MongoDB.
    3. Here Spring Data MongoDB serves as the persistence provider for MongoDB, It provides the necessary abstraction and implementations to work with MongoDB in a Spring application.
  4. Methods to interact with databases :
    1. Query Based: simple by writing the method names.
    2. Criteria API: Helps with making complex queries.

Spring JPA

  1. Spring Data JPA is build on top of JPA, but it is not the implementation of JPA.
  2. The purpose of Spring JPA is to make working with JPA easy.
Controller --> service --> Repository