Querying your Spring Data JPA Repository - Introduction
Tags: java, spring, jpa, repository
Published: 2020-01-06 23:14:36

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](https://docs.oracle.com/en/java/javase/13/) and the [framework](https://spring.io), 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](https://spring.io/projects/spring-data-jpa) of [Spring Data](https://spring.io/projects/spring-data), one of the many (many!) projects of Spring Framework.
- Spring Data JPA Repository: a Java interface/class annotated with `@Repository` from `org.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](https://github.com/brunodrugowick/jpa-queries-blog-post) so you can follow along.

<!-- Remove after completion -->
In the mean time, this post links to another GitHub repository.

### 1. Query Methods

Awesome Spring Data JPA implementation!
 
{% post https://dev.to/brunodrugowick/spring-data-jpa-query-methods-l43 %}

### 2. JPQL within the source code

@Query annotation.

{% post https://dev.to/brunodrugowick/using-jpql-with-spring-data-jpa-48c0 %}

### 3. Externalized JPQL with `orm.xml` file

Well, there's this. =|

{% post https://dev.to/brunodrugowick/using-jpql-on-orm-xml-file-with-spring-data-jpa-39ej %}

### 4. Custom Spring Data JPA Repository method

Java code is added to the mix and dynamic stuff is now possible!

{% post https://dev.to/brunodrugowick/four-steps-to-extend-a-spring-data-jpa-repository-with-your-own-code-53b0 %}

### 5. Use of Criteria API

More dynamic.

- Article (to be written).
- If you consider yourself self-taught, see: [this](https://github.com/brunodrugowick/algafood-api/commit/e19a606fa2db4d7a9ecc297568922922dd5ff70f).

### 6. Use of Specification design pattern

More and more dynamic!

- Article (to be written).
- If you consider yourself self-taught, see: [this](https://github.com/brunodrugowick/algafood-api/commit/9ffb6ecb2c9769dbf76760cf0a0b125ee80064ca).

### 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](https://github.com/brunodrugowick/algafood-api/commit/dad7e2a187d1f3fba56d61793436b5c20d924a74).

### 8. BONUS: use of [Querydsl](http://www.querydsl.com/)

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](https://github.com/brunodrugowick/algafood-api/commit/b771e424b2825e88a6bb7dabd117f7bae609df32).

## Thanks to

Most of what you see here I learnt on a [course from Algaworks (in Portuguese)](https://cafe.algaworks.com/lista-espera-spring-rest/) 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.