SlideShare a Scribd company logo
4
Most read
6
Most read
12
Most read
Presented By: Shashikant Tanti &
Krishna Jaiswal
Lack of etiquette and manners is a huge turn off.
KnolX Etiquettes
Punctuality
Join the session 5 minutes prior
to the session start time. We
start on time and conclude on
time!
Feedback
Make sure to submit a
constructive feedback for all
sessions as it is very helpful for
the presenter.
Silent Mode
Keep your mobile devices in
silent mode, feel free to move
out of session in case you need
to attend an urgent call.
Avoid Disturbance
Avoid unwanted chit chat during
the session.
Agenda
What Spring Data JPA Is?
01
02
03
04
05
What Components Do We Need?
Query Methods
Spring Data Repositories Interfaces
Getting the Required Dependencies
06
Reasons to use Spring Data JPA
06
Demo
07
1.What Spring Data JPA Is?
Spring Data JPA is used to reduce the amount of boilerplate code required to implement the data access
object (DAO) layer.
Spring Data JPA is not a JPA provider. It is a library / framework that adds an extra layer of abstraction on
the top of our JPA provider. If we decide to use Spring Data JPA, the repository layer of our application
contains three layers that are described in the following figure :-
● Spring Data JPA :- It provides support for creating JPA repositories
by extending the Spring Data repository interfaces.
● Spring Data Commons :- It provides the infrastructure that is shared
by the datastore specific Spring Data projects.
● JPA Provider :- The JPA Provider implements the Java Persistence
API.
2. Spring Data Repositories Interfaces
The power of Spring Data JPA lies in the repository abstraction that is provided by the Spring Data
Commons project and extended by the datastore specific sub projects.
We can use Spring Data JPA without paying any attention to the actual implementation of the repository
abstraction, but we have to be familiar with the Spring Data repository interfaces. These interfaces are
described in the following:
3.What Components Do We Need?
If we want to implement a persistence layer that uses Spring Data JPA, we need the following components:
● The JDBC driver provides a database specific implementation of the JDBC API. We use the
MySQL database because it makes our example application easier to run.
● The JPA Provider implements the Java Persistence API. We use Hibernate because it is the most
common JPA provider.
● Spring Data JPA hides the used JPA provider behind its repository abstraction.
4.Getting the Required Dependencies
We can get the required dependencies with Maven by using one of these options:
● We can manage our dependencies by using the Spring IO Platform.
● We can manage our dependencies "manually".
● Configure the required dependencies in the pom.xml file.
Dependencies
<!-- Database (MySQL) -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Spring Data JPA -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
</dependency>
5.Query Methods
Query methods are methods that find information from the database and are declared on the repository
interface. For example, if we want to create a database query that finds the Todo object that has a specific
id, we can create the query method by adding the findById() method to the TodoRepository interface. After
we have done this, our repository interface looks as follows:
import org.springframework.data.repository.Repository;
interface TodoRepository extends Repository<Todo, Long> {
// This is a query method.
Todo findById(Long id);
}
Creating the Properties File
Often we want to use a slightly different configuration in different environments. A good way to do this is move the
configuration to a properties file and use a different properties file in different environments.
The application.properties file contains the configuration that is used to configure our example application. We can create
this properties file by following these steps:
● Configure the database connection of our application. We need to configure the name of the JDBC driver class,
the JDBC url, the username of the database user, and the password of the database user.
● Configure Hibernate by following these steps:
○ Configure the used database dialect.
○ Ensure that Hibernate creates the database when our application is started and drops it when our application
is closed.
○ Configure the naming strategy that is used when Hibernate creates new database objects and schema
elements.
○ Configure the Hibernate to NOT write the invoked SQL statements to the console.
○ Ensure that if Hibernate writes the SQL statements to the console, it will use prettyprint.
The application.properties file looks as follows:
#Database Configuration
1. spring.datasource.driver-class-name = com.mysql.jdbc.Driver
2. spring.datasource.username = ${dbName}
3. spring.datasource.password = ${dbPassword}
4. spring.jpa.show-sql = true
5. spring.datasource.url = jdbc:mysql://localhost:3306/user
#Hibernate Configuration
6. spring.jpa.hibernate.ddl-auto = create
7. spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
6.Reasons to use Spring Data JPA
● No-code Repositories
● Reduced boilerplate code
● Generated queries
● https://blog.knoldus.com/working-with-spring-data-jpa/
● https://www.youtube.com/watch?v=XdMCg6KssXQ
References
Demo
Thank You !
Get in touch with us:
Lorem Studio, Lord Building
D4456, LA, USA

More Related Content

What's hot (20)

PPTX
Spring Boot
Jiayun Zhou
 
PPTX
Introduction to Spring Boot
Purbarun Chakrabarti
 
PDF
Spring Boot
Pei-Tang Huang
 
PPTX
Hibernate ppt
Aneega
 
PDF
Hibernate Presentation
guest11106b
 
PDF
JPA and Hibernate
elliando dias
 
PDF
Spring Framework - Core
Dzmitry Naskou
 
PDF
Spring Boot
HongSeong Jeon
 
PPT
Java EE Introduction
ejlp12
 
PPT
Core java concepts
Ram132
 
PDF
Java 8 Lambda Built-in Functional Interfaces
Ganesh Samarthyam
 
PDF
Spring Data JPA
Cheng Ta Yeh
 
PPT
Spring Core
Pushan Bhattacharya
 
PPTX
Spring boot
sdeeg
 
PDF
Spring Boot
Jaran Flaath
 
PDF
Exception handling
Anna Pietras
 
PPTX
Java 8 streams
Manav Prasad
 
PPTX
Spring Boot and REST API
07.pallav
 
PPT
Jpa
Manav Prasad
 
PPTX
Spring boot
Pradeep Shanmugam
 
Spring Boot
Jiayun Zhou
 
Introduction to Spring Boot
Purbarun Chakrabarti
 
Spring Boot
Pei-Tang Huang
 
Hibernate ppt
Aneega
 
Hibernate Presentation
guest11106b
 
JPA and Hibernate
elliando dias
 
Spring Framework - Core
Dzmitry Naskou
 
Spring Boot
HongSeong Jeon
 
Java EE Introduction
ejlp12
 
Core java concepts
Ram132
 
Java 8 Lambda Built-in Functional Interfaces
Ganesh Samarthyam
 
Spring Data JPA
Cheng Ta Yeh
 
Spring Core
Pushan Bhattacharya
 
Spring boot
sdeeg
 
Spring Boot
Jaran Flaath
 
Exception handling
Anna Pietras
 
Java 8 streams
Manav Prasad
 
Spring Boot and REST API
07.pallav
 
Spring boot
Pradeep Shanmugam
 

Similar to Spring Data JPA (20)

PPTX
Spring data jpa are used to develop spring applications
michaelaaron25322
 
DOCX
Hibernate notes
Rajeev Uppala
 
PDF
Midao JDBC presentation
Zachar Prychoda
 
DOCX
Month 3 report
PRIYANKA FNU
 
PPTX
Managing Data in Jakarta EE Applications
Buhake Sindi
 
PDF
What is hibernate?
kanchanmahajan23
 
PPTX
Hibernate
Mallikarjuna G D
 
DOCX
What is hibernate?
kanchanmahajan23
 
PPTX
Dao example
myrajendra
 
PPTX
java 4 Part 1 computer science.pptx
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
PDF
springdataJpa
Knoldus Inc.
 
PDF
Connect2014 Show104: Practical Java
panagenda
 
PPTX
Spring boot
NexThoughts Technologies
 
PPTX
SpringBootCompleteBootcamp.pptx
SUFYAN SATTAR
 
ODP
Hibernate complete Training
sourabh aggarwal
 
PDF
Spring Boot Tutorial Part 2 (JPA&Hibernate) .pdf
abdelr7man3mad2004
 
PPT
SHOW104: Practical Java
Mark Myers
 
PDF
Data access
Joshua Yoon
 
PDF
Externalized Distributed Configuration Management with Spring Cloud Config-Se...
Nikhil Hiremath
 
PDF
Free Hibernate Tutorial | VirtualNuggets
Virtual Nuggets
 
Spring data jpa are used to develop spring applications
michaelaaron25322
 
Hibernate notes
Rajeev Uppala
 
Midao JDBC presentation
Zachar Prychoda
 
Month 3 report
PRIYANKA FNU
 
Managing Data in Jakarta EE Applications
Buhake Sindi
 
What is hibernate?
kanchanmahajan23
 
Hibernate
Mallikarjuna G D
 
What is hibernate?
kanchanmahajan23
 
Dao example
myrajendra
 
java 4 Part 1 computer science.pptx
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
springdataJpa
Knoldus Inc.
 
Connect2014 Show104: Practical Java
panagenda
 
SpringBootCompleteBootcamp.pptx
SUFYAN SATTAR
 
Hibernate complete Training
sourabh aggarwal
 
Spring Boot Tutorial Part 2 (JPA&Hibernate) .pdf
abdelr7man3mad2004
 
SHOW104: Practical Java
Mark Myers
 
Data access
Joshua Yoon
 
Externalized Distributed Configuration Management with Spring Cloud Config-Se...
Nikhil Hiremath
 
Free Hibernate Tutorial | VirtualNuggets
Virtual Nuggets
 
Ad

More from Knoldus Inc. (20)

PPTX
Angular Hydration Presentation (FrontEnd)
Knoldus Inc.
 
PPTX
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
Knoldus Inc.
 
PPTX
Self-Healing Test Automation Framework - Healenium
Knoldus Inc.
 
PPTX
Kanban Metrics Presentation (Project Management)
Knoldus Inc.
 
PPTX
Java 17 features and implementation.pptx
Knoldus Inc.
 
PPTX
Chaos Mesh Introducing Chaos in Kubernetes
Knoldus Inc.
 
PPTX
GraalVM - A Step Ahead of JVM Presentation
Knoldus Inc.
 
PPTX
Nomad by HashiCorp Presentation (DevOps)
Knoldus Inc.
 
PPTX
Nomad by HashiCorp Presentation (DevOps)
Knoldus Inc.
 
PPTX
DAPR - Distributed Application Runtime Presentation
Knoldus Inc.
 
PPTX
Introduction to Azure Virtual WAN Presentation
Knoldus Inc.
 
PPTX
Introduction to Argo Rollouts Presentation
Knoldus Inc.
 
PPTX
Intro to Azure Container App Presentation
Knoldus Inc.
 
PPTX
Insights Unveiled Test Reporting and Observability Excellence
Knoldus Inc.
 
PPTX
Introduction to Splunk Presentation (DevOps)
Knoldus Inc.
 
PPTX
Code Camp - Data Profiling and Quality Analysis Framework
Knoldus Inc.
 
PPTX
AWS: Messaging Services in AWS Presentation
Knoldus Inc.
 
PPTX
Amazon Cognito: A Primer on Authentication and Authorization
Knoldus Inc.
 
PPTX
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
Knoldus Inc.
 
PPTX
Managing State & HTTP Requests In Ionic.
Knoldus Inc.
 
Angular Hydration Presentation (FrontEnd)
Knoldus Inc.
 
Optimizing Test Execution: Heuristic Algorithm for Self-Healing
Knoldus Inc.
 
Self-Healing Test Automation Framework - Healenium
Knoldus Inc.
 
Kanban Metrics Presentation (Project Management)
Knoldus Inc.
 
Java 17 features and implementation.pptx
Knoldus Inc.
 
Chaos Mesh Introducing Chaos in Kubernetes
Knoldus Inc.
 
GraalVM - A Step Ahead of JVM Presentation
Knoldus Inc.
 
Nomad by HashiCorp Presentation (DevOps)
Knoldus Inc.
 
Nomad by HashiCorp Presentation (DevOps)
Knoldus Inc.
 
DAPR - Distributed Application Runtime Presentation
Knoldus Inc.
 
Introduction to Azure Virtual WAN Presentation
Knoldus Inc.
 
Introduction to Argo Rollouts Presentation
Knoldus Inc.
 
Intro to Azure Container App Presentation
Knoldus Inc.
 
Insights Unveiled Test Reporting and Observability Excellence
Knoldus Inc.
 
Introduction to Splunk Presentation (DevOps)
Knoldus Inc.
 
Code Camp - Data Profiling and Quality Analysis Framework
Knoldus Inc.
 
AWS: Messaging Services in AWS Presentation
Knoldus Inc.
 
Amazon Cognito: A Primer on Authentication and Authorization
Knoldus Inc.
 
ZIO Http A Functional Approach to Scalable and Type-Safe Web Development
Knoldus Inc.
 
Managing State & HTTP Requests In Ionic.
Knoldus Inc.
 
Ad

Recently uploaded (20)

PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 

Spring Data JPA

  • 1. Presented By: Shashikant Tanti & Krishna Jaiswal
  • 2. Lack of etiquette and manners is a huge turn off. KnolX Etiquettes Punctuality Join the session 5 minutes prior to the session start time. We start on time and conclude on time! Feedback Make sure to submit a constructive feedback for all sessions as it is very helpful for the presenter. Silent Mode Keep your mobile devices in silent mode, feel free to move out of session in case you need to attend an urgent call. Avoid Disturbance Avoid unwanted chit chat during the session.
  • 3. Agenda What Spring Data JPA Is? 01 02 03 04 05 What Components Do We Need? Query Methods Spring Data Repositories Interfaces Getting the Required Dependencies 06 Reasons to use Spring Data JPA 06 Demo 07
  • 4. 1.What Spring Data JPA Is? Spring Data JPA is used to reduce the amount of boilerplate code required to implement the data access object (DAO) layer. Spring Data JPA is not a JPA provider. It is a library / framework that adds an extra layer of abstraction on the top of our JPA provider. If we decide to use Spring Data JPA, the repository layer of our application contains three layers that are described in the following figure :-
  • 5. ● Spring Data JPA :- It provides support for creating JPA repositories by extending the Spring Data repository interfaces. ● Spring Data Commons :- It provides the infrastructure that is shared by the datastore specific Spring Data projects. ● JPA Provider :- The JPA Provider implements the Java Persistence API.
  • 6. 2. Spring Data Repositories Interfaces The power of Spring Data JPA lies in the repository abstraction that is provided by the Spring Data Commons project and extended by the datastore specific sub projects. We can use Spring Data JPA without paying any attention to the actual implementation of the repository abstraction, but we have to be familiar with the Spring Data repository interfaces. These interfaces are described in the following:
  • 7. 3.What Components Do We Need? If we want to implement a persistence layer that uses Spring Data JPA, we need the following components: ● The JDBC driver provides a database specific implementation of the JDBC API. We use the MySQL database because it makes our example application easier to run. ● The JPA Provider implements the Java Persistence API. We use Hibernate because it is the most common JPA provider. ● Spring Data JPA hides the used JPA provider behind its repository abstraction.
  • 8. 4.Getting the Required Dependencies We can get the required dependencies with Maven by using one of these options: ● We can manage our dependencies by using the Spring IO Platform. ● We can manage our dependencies "manually". ● Configure the required dependencies in the pom.xml file.
  • 9. Dependencies <!-- Database (MySQL) --> <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <!-- Spring Data JPA --> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-jpa</artifactId> </dependency>
  • 10. 5.Query Methods Query methods are methods that find information from the database and are declared on the repository interface. For example, if we want to create a database query that finds the Todo object that has a specific id, we can create the query method by adding the findById() method to the TodoRepository interface. After we have done this, our repository interface looks as follows: import org.springframework.data.repository.Repository; interface TodoRepository extends Repository<Todo, Long> { // This is a query method. Todo findById(Long id); }
  • 11. Creating the Properties File Often we want to use a slightly different configuration in different environments. A good way to do this is move the configuration to a properties file and use a different properties file in different environments. The application.properties file contains the configuration that is used to configure our example application. We can create this properties file by following these steps: ● Configure the database connection of our application. We need to configure the name of the JDBC driver class, the JDBC url, the username of the database user, and the password of the database user. ● Configure Hibernate by following these steps: ○ Configure the used database dialect. ○ Ensure that Hibernate creates the database when our application is started and drops it when our application is closed. ○ Configure the naming strategy that is used when Hibernate creates new database objects and schema elements. ○ Configure the Hibernate to NOT write the invoked SQL statements to the console. ○ Ensure that if Hibernate writes the SQL statements to the console, it will use prettyprint.
  • 12. The application.properties file looks as follows: #Database Configuration 1. spring.datasource.driver-class-name = com.mysql.jdbc.Driver 2. spring.datasource.username = ${dbName} 3. spring.datasource.password = ${dbPassword} 4. spring.jpa.show-sql = true 5. spring.datasource.url = jdbc:mysql://localhost:3306/user #Hibernate Configuration 6. spring.jpa.hibernate.ddl-auto = create 7. spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
  • 13. 6.Reasons to use Spring Data JPA ● No-code Repositories ● Reduced boilerplate code ● Generated queries
  • 15. Demo
  • 16. Thank You ! Get in touch with us: Lorem Studio, Lord Building D4456, LA, USA