DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Data Engineering
  3. Data
  4. What Is Spring Data JPA?

What Is Spring Data JPA?

If you're integrating an ORM into your Spring application, then you should know about Spring Data JPA.

Zoltan Raffai user avatar by
Zoltan Raffai
·
Nov. 20, 18 · Presentation
Like (12)
Save
Tweet
Share
30.24K Views

Join the DZone community and get the full member experience.

Join For Free

In this article, I would like to talk about the Spring Data JPA (Java Persistence API). This library is one of the main building blocks of the Spring framework. It is also a powerful tool that you should know about if you would like to work with persistent data.

I often see that developers who actually use it do not see the whole picture. They miss using some of the most useful abilities of it. Hence, I would like to show you the bigger picture as well as the most meaningful tools to handle your persistent data across your application.

If you are not familiar with Java Spring yet, I recommend you to check out my previous article about it here.

How Long Can a Simple CRUD Repository Be?

Before we jump in, I would like to share a quick introspection on what this framework is capable of doing. Let's see the following code snippet below.

Image title

The picture shows the amount of code needed to handle inserting, updating, deleting, and reading data from a single database table using a standard JPA entity model.

These are also known as standard CRUD operations. CRUD is an acronym for Create, Read, Update, and Delete. We also implemented some custom queries in this class that perform various data filtering with this JPA entity. All in all, this is a pretty standard code to build up a persistence tier with JPA in Java.

How Long Is It With Spring Data JPA?

By including and implementing Spring Data JPA into your project, you can remove all of the code and replace it with the following:

We went down from almost 50 lines of code to 5 lines of code without losing any of the functionality. This should give you an idea of how powerful this framework is.

What Is Spring Data JPA?

After we got a taste of what we can achieve with this library, let's talk about how it works is and how it connects to the Java Spring ecosystem.

As I mentioned before, it is considered one of the core projects in Spring's suite of tools.

Spring Data JPA also builds upon and enhances JPA, which stands for Java Persistence API.

Spring Data JPA Features

Most applications have some kind of data store. As your application complexity and feature set grows, you will find that your Data Access Layer and persistence tier code will also grow.

Simplifies Data Access Layer

One of the core objectives of Spring Data JPA is to reduce your code and simplify your Data Access Layer, while still maintaining a rich and full-featured set of functionality.

Intelligent Spring Repository Stereotyped Interfaces

To make this possible, Spring DATA JPA allows you to build intelligent Spring Repository stereotyped interfaces. These repositories are Java interfaces that allow you to define a data access contract.

The Spring Data JPA framework then inspects that contract and automatically builds the interface implementation under the covers for you.

Query DSL

To generate an implementation of your Repository interface, it needs a Query DSL. DSL is an acronym for Domain Specific Language.

The Query Domain Specific Language allows you to create Java interface methods that utilize certain keywords along with JPA entity attributes to perform the work needed.

Auditing, Paging, Handling Native SQL Queries

Spring Data JPA also provides some nice extras, such as auditing, paging, and handling of native SQL queries.

Gets Out of the Way, if Needed

If you need to do something that the Spring Data provider cannot do, it can easily get out of the way and let you code your own implementations.

Summary

In this article, we went through the capabilities of the Spring Data JPA. You got some introspection how it relates to the Spring Framework and the Java Persistence API. I also showed you a quick example of how drastically it can decrease the line of codes of a standard JPA class by serving the same functionality.

For more deeper knowledge I recommend you to read the official Spring documentation here.

In my upcoming articles, I will dive deeper into its' functionalities with provided examples. Stay tuned!

Spring Framework Spring Data Data (computing)

Published at DZone with permission of Zoltan Raffai, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • PostgreSQL: Bulk Loading Data With Node.js and Sequelize
  • Key Considerations When Implementing Virtual Kubernetes Clusters
  • Top Five Tools for AI-based Test Automation
  • Debugging Threads and Asynchronous Code

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: