DEV Community

Cover image for Let's Decode ORM, ORM Tools, JPA and Spring Data JPA | Spring Boot | Java Spring
Debesh P.
Debesh P.

Posted on

1 1 1 1

Let's Decode ORM, ORM Tools, JPA and Spring Data JPA | Spring Boot | Java Spring

ORM:

ORM, means Object-Relational Mapping. ORM is a technique used to map Java objects to database (relational) tables. It allows developers to work with databases using Object-Oriented Programming (OOP) concepts, making it easier to interact with relational (e.g. MySQL) databases.

Consider a Java class User and a database table users. ORM frameworks 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 records.

JPA:

JPA, also known as Java Persistence API. Let's try to break it down in simplest way! Java is our programming language, Persistence means permanently storing the data, and API is some set of rules.

JPA is a way to achieve ORM, includes interfaces and annotations that you use in your Java classes, requires a persistence provider (ORM tools) for implementation.

ORM Tools (Persistence Provider):

To use JPA, you need a persistence provider. A persistence provider is a specific implementation of the JPA specification.

Examples of JPA persistence providers include Hibernate, EclipseLink and OpenJPA. These providers implement the JPA interfaces and provide the underlying functionality to interact with databases.

Spring Data JPA:

Spring Data JPA is built on top of the JPA (Java Persistence API) specification, but it is not a JPA implementation itself. Instead, it simplifies working with JPA by providing higher-level abstractions and utilities.

However, to use Spring Data JPA effectively, you still need a JPA implementation, such as Hibernate, EclipseLink or another JPA-compliant provider, to handle the actual database interactions.

JPA is primarily designed for working with relational databases, where data is stored in tables with a predefined schema. MongoDB, on the the other hand, is a NoSQL database that uses a different data model, typically used on collections of documents which are schema-less or have flexible schemas. This fundamental difference in data models and storage structures is why, JPA is not used with MongoDB.

In the case of MongoDB, you don't have a traditional JPA persistence provider. MongoDB is a NoSQL database, and Spring Data MongoDB serves as the "persistence provider" for MongoDB. It provides the necessary abstractions and implementations to work with MongoDB in a Spring application.

Spring Data MongoDB

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-mongodb</artifact>
</dependency>
Enter fullscreen mode Exit fullscreen mode

Query Method DSL and Criteria API are two different ways to interact with a database when using Spring Data JPA for relational databases and Spring Data MongoDB for MongoDB databases.

Spring Data JPA is a part of the Spring Framework that simplifies data access in Java application, while Spring Data MongoDB provides similar functionality for MongoDB.

Query Method DSL is a simple and convenient way to create queries based on method naming conventions, while Criteria API offers a more dynamic and programmatic approach for building complex and custom queries.

Heroku

Deploy with ease. Manage efficiently. Scale faster.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (1)

Collapse
 
debeshpg90 profile image
Debesh P.

connect with me on LinkedIn 🙌

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay