Querydsl Extension
Learn to add statically typed SQL-like queries using the Querydsl extension.
Querydsl is a Java framework to create database queries that are type-safe, similar to SQL, and easy to read and implement.
Querydsl dependencies in build.gradle
First, let’s add the dependencies to the build.gradle
file to add Querydsl support to our Spring Data project.
Press + to interact
plugins {id 'java'id 'org.springframework.boot' version '3.0.2'id 'io.spring.dependency-management' version '1.1.0'}group = 'com.smartdiscover'version = '0.0.1-SNAPSHOT'sourceCompatibility = '17'repositories {mavenCentral()}dependencies {implementation 'org.springframework.boot:spring-boot-starter-data-jpa'implementation 'org.projectlombok:lombok:1.18.26'annotationProcessor 'org.projectlombok:lombok'runtimeOnly 'com.h2database:h2'implementation "com.querydsl:querydsl-core:5.0.0"implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'annotationProcessor 'com.querydsl:querydsl-apt:5.0.0:jakarta'annotationProcessor "jakarta.persistence:jakarta.persistence-api"}
Explanation:
- Lines 21 and 22: We add the
querydsl-core
andquerydsl-jpa
dependencies along with thejakarta
API support. - Lines 23 and 24: We set the
forannotation processor Annotation processors in Gradle build automatic code generation and perform tasks based on annotations present in the source code, enhancing project functionality. querydsl-apt
andjakarta.persistence-api
.
So, when we build our Spring Data application using Gradle’s build
command, Querydsl will scan for the classes annotated with the @Entity
annotation and automatically generate the query classes for them.
In our project, ...
Get hands-on with 1400+ tech skills courses.