Querying your Spring Data JPA Repository - Introduction
[java, spring, jpa, repository]
You'll have a better experience reading in DEV
Click here to continue reading this post there >>
However, if you want to know more about the project to mirror my posts from DEV here (and why), go ahead and read more.
You can continue to read here too, it's up to you... =]
In this series of posts I'll show you several methods to query your Java
JPA
repositories
using Spring Data JPA
. Throwing in some Spring Boot
and JPQL
and you have too many words!
So... what do you need to know?
- Java and Spring: the language and the framework, respectively.
- Java Persistence API (JPA): the specification for a ORM (Object-Relational Mapping) born from Hibernate, the first and most popular implementation of the JPA specification.
- It's how you persist data to a relational database.
- Spring Data JPA: a sub-project of Spring Data, one of the many (many!) projects of Spring Framework.
- Spring Data JPA Repository: a Java interface/class annotated with
@Repository
fromorg.springframework.stereotype
package.
Also noteworthy:
- Spring Boot: opinionated modules of the Spring Framework and third-party libraries. It means the libraries come with sensible defaults so you kick-start your development without much configuration of libraries.
- Java Persistence Query Language (JPQL): a query language similar to SQL. I don't know much more than what you'll see here in this series of posts.
If this brief explanation is not sufficient for you to comfortably continue reading, please, let me know and I'll do my best to update with more links and references (or maybe even write something).
Otherwise, you may continue on this awesome series of posts! =P
Content
I'm going to cover 8 methods to query your data using Spring Data JPA Repositories. I'll develop an app for this series of posts so you can follow along.
In the mean time, this post links to another GitHub repository.
1. Query Methods
Awesome Spring Data JPA implementation!
2. JPQL within the source code
@Query annotation.
3. Externalized JPQL with orm.xml
file
Well, there's this. =|
Using JPQL on orm.xml file with Spring Data JPA
Bruno Drugowick ・ Feb 11 '20 ・ 2 min read
4. Custom Spring Data JPA Repository method
Java code is added to the mix and dynamic stuff is now possible!
Three steps to extend a Spring Data JPA repository with your own code
Bruno Drugowick ・ Feb 21 '20 ・ 5 min read
5. Use of Criteria API
More dynamic.
- Article (to be written).
- If you consider yourself self-taught, see: this.
6. Use of Specification design pattern
More and more dynamic!
- Article (to be written).
- If you consider yourself self-taught, see: this.
7. Overriding Spring's default implementation for JpaRepository
Now you'll feel like a JPA god!
- Article (to be written).
- If you consider yourself self-taught, see: this.
8. BONUS: use of Querydsl
I don't even know what this is right now but I'll figure it out. Looks cool, though!
- Article (to be written).
- If you consider yourself self-taught, see: to be developed.
Thanks to
Most of what you see here I learnt on a course from Algaworks (in Portuguese) about REST APIs with Spring, where JPA is a huge section. I recommend the course if you speak Portuguese.
Not Included
I won't cover any of this:
- Database configuration.
- Spring Boot app creation.
- Entity relationships.
- Etc...
Nevertheless, I'll provide a public GitHub repository with everything that I mention here and also would love to help if you drop a question on the Comments section.
…