SlideShare a Scribd company logo
1 of 15
Spring Data in 10 minutes
Corneil du Plessis
corneil.duplessis@gmail.com
about.me/corneil
@corneil
Introduction
● Assumptions
– You know JPA the Java Persistence API
– You know the Spring Framework or Dependency
Injection
● Take away
– Some appreciation for polyglot persistence
– Some understanding of Spring Data
What is Polyglot persistence?
● RDBMS doesn't scale to Internet (millions of users and billions of
transactions).
● Ability to interact with multiple data stores depending on specific use
cases
● MongoDB or Couchbase for Customer data
● RDBMS for financial transactions
● Elasticsearch, Cassandra or HBase for site clicks and audit trails
● Hadoop for Big Data
● Neo4J, OrientDB for Graph Data
● RDF Stores for Semantic Reasoning
Why Spring Data?
● Best practice indicates you should have Data Access
Components or a Data Service Layer.
● How often do you make simple mistakes interacting with
EntityManager?
● Different API for each store.
● It should be easier...
What is Spring Data?
● Spring Data is an open source project managed by
SpringSource.
● Spring Data relies on Spring Framework.
● Spring Data provides a set of common patterns for
persisting data using existing libraries.
● Spring Data provides a Repository Interface
● Spring Data provides finder methods
● Spring Data provides support for QueryDSL
● Spring Data simplifies polyglot persistence
Spring Data sub projects
● Commons
● JPA
● JDBC Extensions
● MongoDB
● Neo4J
● Redis
● HBase
● Hadoop
● GemFire
● REST provider
● Community Projects
– OrientDB
– RDF
– Couchbase
– Cassandra
– Elasticsearch
– DynamoDB
How Spring Data?
● Configure Spring Data for specific technology
● Define Entity as per relevant library
● Declare Repository Interface
● Spring Data will provide Repository Implementation
● Spring Framework will inject Repository implementation
where needed
Spring Data Samples – Configuration
● EntityManagerFactory as normal for JPA
● <jpa:repositories
base-package="...springdata.demo" />
OR
● @EnableJpaRepositories("...springdata.demo")
Spring Data Sample – Entity
● @Entity
public class User {
@Id
Long id;
String fullName;
String gender;
Date dateOfBirth;
}
Spring Data Sample – Repository
● @Repository
public interface UserRepository
extends CrudRepository<User> {
}
● Crud Repository provides type-safe methods for save,
delete, load
Spring Data Sample - Injection
● @Service
public class MyDataServiceImpl {
@AutoWired
protected UserRepository userRepo;
public void saveUser(User user) {
userRepo.save(user);
}
}
Spring Data Sample – Finders
● @Repository
public interface UserRepository
extends CrudRepository<User> {
List<User> findByGender(
String genderCode);
List<User> findByDateOfBirthBetween(
Date startDate, Date endDate);
}
● Crud Repository provides query predicates based on method
name like:
findByNameOrderByDateOfBirthDesc
findByNameORSurname
Spring Data Sample – QueryDSL
● @Entity
@QueryEntity
public class User {
@Id
private Long id;
private String fullName;
private String gender;
private Date dateOfBirth;
}
● QueryDSL generates QUser for creating type-safe query.
● import static Quser.*;
List<User> users = userRepo.findAll(user.gender.eq('M'))
Spring Data – Notes
● User code is same on MongoDB, JPA, Neo4J, Redis etc.
● Entity Mapping is usually specific to technology.
● Common Repository methods can be implemented.
● Implementation specific queries:
@Query(“select * from User u where u.gender = ?”)
List<User> findUsersForGender(String code)
Spring Data – Questions
● Demo code at
https://github.com/corneil/spring-data-demo
● Please Star the repo on github.com if you like the project.
● Like the slides on Slideshare

More Related Content

What's hot

Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate Tutorial
Ram132
 
Introduction to hibernate
Introduction to hibernateIntroduction to hibernate
Introduction to hibernate
hr1383
 
Powerful persistence layer with Google Guice & MyBatis
Powerful persistence layer with Google Guice & MyBatisPowerful persistence layer with Google Guice & MyBatis
Powerful persistence layer with Google Guice & MyBatis
simonetripodi
 
Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate Tutorial
Syed Shahul
 

What's hot (20)

Hibernate Basic Concepts - Presentation
Hibernate Basic Concepts - PresentationHibernate Basic Concepts - Presentation
Hibernate Basic Concepts - Presentation
 
Polyglot persistence with Spring Data
Polyglot persistence with Spring DataPolyglot persistence with Spring Data
Polyglot persistence with Spring Data
 
hibernate with JPA
hibernate with JPAhibernate with JPA
hibernate with JPA
 
Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate Tutorial
 
Data repositories
Data repositoriesData repositories
Data repositories
 
Spring framework part 2
Spring framework part 2Spring framework part 2
Spring framework part 2
 
Introduction to hibernate
Introduction to hibernateIntroduction to hibernate
Introduction to hibernate
 
Introduction to Datastore
Introduction to DatastoreIntroduction to Datastore
Introduction to Datastore
 
JNDI
JNDIJNDI
JNDI
 
Consume Spring Data Rest with Angularjs
Consume Spring Data Rest with AngularjsConsume Spring Data Rest with Angularjs
Consume Spring Data Rest with Angularjs
 
Json
Json Json
Json
 
Xml parsers
Xml parsersXml parsers
Xml parsers
 
JPA 2.1 performance tuning tips
JPA 2.1 performance tuning tipsJPA 2.1 performance tuning tips
JPA 2.1 performance tuning tips
 
Powerful persistence layer with Google Guice & MyBatis
Powerful persistence layer with Google Guice & MyBatisPowerful persistence layer with Google Guice & MyBatis
Powerful persistence layer with Google Guice & MyBatis
 
Client Server Communication on iOS
Client Server Communication on iOSClient Server Communication on iOS
Client Server Communication on iOS
 
JDBC Part - 2
JDBC Part - 2JDBC Part - 2
JDBC Part - 2
 
Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate Tutorial
 
Hibernate working with criteria- Basic Introduction
Hibernate working with criteria- Basic IntroductionHibernate working with criteria- Basic Introduction
Hibernate working with criteria- Basic Introduction
 
Query DSL In Elasticsearch
Query DSL In ElasticsearchQuery DSL In Elasticsearch
Query DSL In Elasticsearch
 
Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8Reactive Access to MongoDB from Java 8
Reactive Access to MongoDB from Java 8
 

Viewers also liked

Spring + JPA + DAO Step by Step
Spring + JPA + DAO Step by StepSpring + JPA + DAO Step by Step
Spring + JPA + DAO Step by Step
Guo Albert
 

Viewers also liked (6)

Spring Data - Intro (Odessa Java TechTalks)
Spring Data - Intro (Odessa Java TechTalks)Spring Data - Intro (Odessa Java TechTalks)
Spring Data - Intro (Odessa Java TechTalks)
 
Gradle: The Build System you have been waiting for!
Gradle: The Build System you have been waiting for!Gradle: The Build System you have been waiting for!
Gradle: The Build System you have been waiting for!
 
Spring + JPA + DAO Step by Step
Spring + JPA + DAO Step by StepSpring + JPA + DAO Step by Step
Spring + JPA + DAO Step by Step
 
Spring Data Jpa
Spring Data JpaSpring Data Jpa
Spring Data Jpa
 
Spring Data Jpa
Spring Data JpaSpring Data Jpa
Spring Data Jpa
 
What is tackled in the Java EE Security API (Java EE 8)
What is tackled in the Java EE Security API (Java EE 8)What is tackled in the Java EE Security API (Java EE 8)
What is tackled in the Java EE Security API (Java EE 8)
 

Similar to Spring Data in 10 minutes

ArangoDB – A different approach to NoSQL
ArangoDB – A different approach to NoSQLArangoDB – A different approach to NoSQL
ArangoDB – A different approach to NoSQL
ArangoDB Database
 

Similar to Spring Data in 10 minutes (20)

Spring.io
Spring.ioSpring.io
Spring.io
 
Headless approach for offloading heavy tasks in Magento
Headless approach for offloading heavy tasks in MagentoHeadless approach for offloading heavy tasks in Magento
Headless approach for offloading heavy tasks in Magento
 
Making Hadoop Realtime by Dr. William Bain of Scaleout Software
Making Hadoop Realtime by Dr. William Bain of Scaleout SoftwareMaking Hadoop Realtime by Dr. William Bain of Scaleout Software
Making Hadoop Realtime by Dr. William Bain of Scaleout Software
 
AWS November Webinar Series - Advanced Analytics with Amazon Redshift and the...
AWS November Webinar Series - Advanced Analytics with Amazon Redshift and the...AWS November Webinar Series - Advanced Analytics with Amazon Redshift and the...
AWS November Webinar Series - Advanced Analytics with Amazon Redshift and the...
 
Elements for an iOS Backend
Elements for an iOS BackendElements for an iOS Backend
Elements for an iOS Backend
 
IDE.pptx
IDE.pptxIDE.pptx
IDE.pptx
 
AWS Big Data Demystified #1: Big data architecture lessons learned
AWS Big Data Demystified #1: Big data architecture lessons learned AWS Big Data Demystified #1: Big data architecture lessons learned
AWS Big Data Demystified #1: Big data architecture lessons learned
 
Java one 2010
Java one 2010Java one 2010
Java one 2010
 
Big Data and Machine Learning with FIWARE
Big Data and Machine Learning with FIWAREBig Data and Machine Learning with FIWARE
Big Data and Machine Learning with FIWARE
 
ArangoDB – A different approach to NoSQL
ArangoDB – A different approach to NoSQLArangoDB – A different approach to NoSQL
ArangoDB – A different approach to NoSQL
 
A Tool For Big Data Analysis using Apache Spark
A Tool For Big Data Analysis using Apache SparkA Tool For Big Data Analysis using Apache Spark
A Tool For Big Data Analysis using Apache Spark
 
Experiences with Evangelizing Java Within the Database
Experiences with Evangelizing Java Within the DatabaseExperiences with Evangelizing Java Within the Database
Experiences with Evangelizing Java Within the Database
 
Presto
PrestoPresto
Presto
 
How to create custom dashboards in Elastic Search / Kibana with Performance V...
How to create custom dashboards in Elastic Search / Kibana with Performance V...How to create custom dashboards in Elastic Search / Kibana with Performance V...
How to create custom dashboards in Elastic Search / Kibana with Performance V...
 
IoT databases - review and challenges - IoT, Hardware & Robotics meetup - onl...
IoT databases - review and challenges - IoT, Hardware & Robotics meetup - onl...IoT databases - review and challenges - IoT, Hardware & Robotics meetup - onl...
IoT databases - review and challenges - IoT, Hardware & Robotics meetup - onl...
 
Building data pipelines
Building data pipelinesBuilding data pipelines
Building data pipelines
 
Proud to be polyglot
Proud to be polyglotProud to be polyglot
Proud to be polyglot
 
Building a data pipeline to ingest data into Hadoop in minutes using Streamse...
Building a data pipeline to ingest data into Hadoop in minutes using Streamse...Building a data pipeline to ingest data into Hadoop in minutes using Streamse...
Building a data pipeline to ingest data into Hadoop in minutes using Streamse...
 
SoftwareUniversity seminar fast REST Api with Spring
SoftwareUniversity seminar fast REST Api with SpringSoftwareUniversity seminar fast REST Api with Spring
SoftwareUniversity seminar fast REST Api with Spring
 
Using Spring Data and MongoDB with Cloud Foundry
Using Spring Data and MongoDB with Cloud FoundryUsing Spring Data and MongoDB with Cloud Foundry
Using Spring Data and MongoDB with Cloud Foundry
 

More from Corneil du Plessis

Dependency Injection in Spring in 10min
Dependency Injection in Spring in 10minDependency Injection in Spring in 10min
Dependency Injection in Spring in 10min
Corneil du Plessis
 

More from Corneil du Plessis (11)

Sweet Streams (Are made of this)
Sweet Streams (Are made of this)Sweet Streams (Are made of this)
Sweet Streams (Are made of this)
 
Cloud Native Applications for Cloud Foundry using Spring Cloud : A Workshop
Cloud Native Applications for Cloud Foundry using Spring Cloud : A WorkshopCloud Native Applications for Cloud Foundry using Spring Cloud : A Workshop
Cloud Native Applications for Cloud Foundry using Spring Cloud : A Workshop
 
QueryDSL - Lightning Talk
QueryDSL - Lightning TalkQueryDSL - Lightning Talk
QueryDSL - Lightning Talk
 
Enhancements in Java 9 Streams
Enhancements in Java 9 StreamsEnhancements in Java 9 Streams
Enhancements in Java 9 Streams
 
Reactive Spring 5
Reactive Spring 5Reactive Spring 5
Reactive Spring 5
 
Empathic API-Design
Empathic API-DesignEmpathic API-Design
Empathic API-Design
 
Performance Comparison JVM Languages
Performance Comparison JVM LanguagesPerformance Comparison JVM Languages
Performance Comparison JVM Languages
 
Microservices Patterns and Anti-Patterns
Microservices Patterns and Anti-PatternsMicroservices Patterns and Anti-Patterns
Microservices Patterns and Anti-Patterns
 
The Evolution of Java
The Evolution of JavaThe Evolution of Java
The Evolution of Java
 
Gradle: The Build system you have been waiting for
Gradle: The Build system you have been waiting forGradle: The Build system you have been waiting for
Gradle: The Build system you have been waiting for
 
Dependency Injection in Spring in 10min
Dependency Injection in Spring in 10minDependency Injection in Spring in 10min
Dependency Injection in Spring in 10min
 

Recently uploaded

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 

Recently uploaded (20)

HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 

Spring Data in 10 minutes

  • 1. Spring Data in 10 minutes Corneil du Plessis corneil.duplessis@gmail.com about.me/corneil @corneil
  • 2. Introduction ● Assumptions – You know JPA the Java Persistence API – You know the Spring Framework or Dependency Injection ● Take away – Some appreciation for polyglot persistence – Some understanding of Spring Data
  • 3. What is Polyglot persistence? ● RDBMS doesn't scale to Internet (millions of users and billions of transactions). ● Ability to interact with multiple data stores depending on specific use cases ● MongoDB or Couchbase for Customer data ● RDBMS for financial transactions ● Elasticsearch, Cassandra or HBase for site clicks and audit trails ● Hadoop for Big Data ● Neo4J, OrientDB for Graph Data ● RDF Stores for Semantic Reasoning
  • 4. Why Spring Data? ● Best practice indicates you should have Data Access Components or a Data Service Layer. ● How often do you make simple mistakes interacting with EntityManager? ● Different API for each store. ● It should be easier...
  • 5. What is Spring Data? ● Spring Data is an open source project managed by SpringSource. ● Spring Data relies on Spring Framework. ● Spring Data provides a set of common patterns for persisting data using existing libraries. ● Spring Data provides a Repository Interface ● Spring Data provides finder methods ● Spring Data provides support for QueryDSL ● Spring Data simplifies polyglot persistence
  • 6. Spring Data sub projects ● Commons ● JPA ● JDBC Extensions ● MongoDB ● Neo4J ● Redis ● HBase ● Hadoop ● GemFire ● REST provider ● Community Projects – OrientDB – RDF – Couchbase – Cassandra – Elasticsearch – DynamoDB
  • 7. How Spring Data? ● Configure Spring Data for specific technology ● Define Entity as per relevant library ● Declare Repository Interface ● Spring Data will provide Repository Implementation ● Spring Framework will inject Repository implementation where needed
  • 8. Spring Data Samples – Configuration ● EntityManagerFactory as normal for JPA ● <jpa:repositories base-package="...springdata.demo" /> OR ● @EnableJpaRepositories("...springdata.demo")
  • 9. Spring Data Sample – Entity ● @Entity public class User { @Id Long id; String fullName; String gender; Date dateOfBirth; }
  • 10. Spring Data Sample – Repository ● @Repository public interface UserRepository extends CrudRepository<User> { } ● Crud Repository provides type-safe methods for save, delete, load
  • 11. Spring Data Sample - Injection ● @Service public class MyDataServiceImpl { @AutoWired protected UserRepository userRepo; public void saveUser(User user) { userRepo.save(user); } }
  • 12. Spring Data Sample – Finders ● @Repository public interface UserRepository extends CrudRepository<User> { List<User> findByGender( String genderCode); List<User> findByDateOfBirthBetween( Date startDate, Date endDate); } ● Crud Repository provides query predicates based on method name like: findByNameOrderByDateOfBirthDesc findByNameORSurname
  • 13. Spring Data Sample – QueryDSL ● @Entity @QueryEntity public class User { @Id private Long id; private String fullName; private String gender; private Date dateOfBirth; } ● QueryDSL generates QUser for creating type-safe query. ● import static Quser.*; List<User> users = userRepo.findAll(user.gender.eq('M'))
  • 14. Spring Data – Notes ● User code is same on MongoDB, JPA, Neo4J, Redis etc. ● Entity Mapping is usually specific to technology. ● Common Repository methods can be implemented. ● Implementation specific queries: @Query(“select * from User u where u.gender = ?”) List<User> findUsersForGender(String code)
  • 15. Spring Data – Questions ● Demo code at https://github.com/corneil/spring-data-demo ● Please Star the repo on github.com if you like the project. ● Like the slides on Slideshare