Table of Contents
Spring Data JPA is an implementation of Java Persistence API for data storage and retrieval and this article is about to provide a detailed explanation of spring data JPA with examples.
Spring Data JPA provides support for SQL and No-SQL databases. So in this tutorial, we will learn Spring JPA with SQL as well as No-SQL database. We are going to explain examples like,
how to create a dynamic query in JPA,
how to apply projection,
In and like query in spring data JPA.
NOTE: In this tutorial, all the example using spring boot and spring JPA but we can also use spring JPA without spring boot.
Spring data JPA supports SQL databases like, MySQL, PostgreSQL, Oracle, MSSQL etc. To configure SQL database we need to configure specific database driver.
Spring data JPA supports NoSQL databases like, MongoDB, Neo4J, Elasticsearch, Solr, Redis, Gemfire, Cassandra, Couchbase and LDAP. If you are new to Spring data JPA then it is worth to read No-SQL support for spring JPA.
- Without spring boot application: In order to implement spring JPA without spring boot application we need to add the dependency groupId:
spring-data-jpain Maven or Gradle tools.
- With spring boot application: For implementing spring JPA with spring boot application we need to add the dependency groupId:
spring-boot-starter-data-jpain Maven or Gradle tools. We have explained with details in our how to create JSON web service with Spring JPA article.
2. Spring JPA with SQL database
- Working with SQL or No-SQL databases, We need to fetch data based on our application requirements, i.e. Like query, In Query etc. We also need dynamic query based on user input from the user interface. We also need to use projection for fetching limited number of the columns from specific tables.
- Nowadays, Multi-tenancy application is implemented everywhere, In a Multi-tenancy architecture, a single application can connect to the database based on dynamic parameters and each client connects to a separate database which might be decided at run time. If you are interested in learning more about multi-tenancy then we have explained in our previous tutorial of multi-tenancy application using spring JPA.
- List of articles for Spring JPA with No-SQL database:
2.1 Database Migration
Database migration is not directly part of spring JPA but while working with the database, We always require to update the database schema so here we have explained some of the SQL database migration tools like flyway and liquibase.
- Spring boot flyway example
- Spring boot liquibase example
- Flyway Repeatable Migration Example
- Spring boot Flyway Java Based Migration Example
3. Spring JPA with No-SQL database
- As we discussed Spring JPA supports No-SQL database as well, Here is an example of spring JPA with elastic search, Elastic is very popular and widely used indexing and searching tool. Here are some of the key features of elastic search which may help you to get more details about Elastic Search.
- Another Popular Indexing and Searching tool is Solr which is also supported by Spring Data JPA, Here is an example and detail explanation about spring JPA with Solr. we also explained some key features of solr.
- List of articles for Spring JPA No-SQL database:
This spring data JPA tutorial may help you learn Spring JPA with examples and it also provides better insight for Spring Data JPA.