Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Data JPA - Specifications and Querydsl

Tags:

I'm trying to integrate QueryDSL to my existing project with Spring Data, I've tried different samples and now I've decided to stick to this one Advanced Spring Data JPA - Specifications and Querydsl.

Problem: when I run the project as Maven generate-sources I get this error

error: Annotation processor 'com.mysema.query.apt.jpa.JPAAnnotationProcessor' not found 

I'm adding this plugin to my pom.xml as the blog post indicates:

<plugin>   <groupId>com.mysema.maven</groupId>   <artifactId>maven-apt-plugin</artifactId>   <version>1.0</version>   <executions>     <execution>       <phase>generate-sources</phase>       <goals>         <goal>process</goal>       </goals>       <configuration>         <outputDirectory>target/generated-sources</outputDirectory>         <processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>       </configuration>     </execution>   </executions> </plugin> 

and the dependency:

<dependency>      <groupId>com.mysema.querydsl</groupId>      <artifactId>querydsl-sql</artifactId>      <version>3.6.9</version> </dependency> 

Can anyone point me in the right direction on how to solve this or how to properly integrate QueryDSL to my project ? Thanks in advance!

like image 853
M.Octavio Avatar asked Nov 16 '15 17:11

M.Octavio


People also ask

What is JPA spring data specification?

SPring Data Jpa Specifications helps us to create dynamic queries based on the requirement at run time. Spring Data Jpa Specifications allows a combination of the attributes or properties of a domain or entity class and creates a query.

What is Querydsl JPA?

Querydsl is an extensive Java framework, which allows for the generation of type-safe queries in a syntax similar to SQL. It currently has a wide range of support for various backends through the use of separate modules including JPA, JDO, SQL, Java collections, RDF, Lucene, Hibernate Search, and MongoDB.

What is Querydsl spring?

Querydsl is a framework that enables the construction of statically typed SQL-like queries through its fluent API. Spring Data modules offer integration with Querydsl through QuerydslPredicateExecutor .

What is difference between JpaRepository and CrudRepository?

CrudRepository: provides CRUD functions. PagingAndSortingRepository: provides methods to do pagination and sort records. JpaRepository: provides JPA related methods such as flushing the persistence context and delete records in a batch.


1 Answers

The way I could make this work was using the com.querydsl.apt.jpa.JPAAnnotationProcessor instead of the com.mysema.query.apt.jpa.JPAAnnotationProcessor and by changing the dependencies as follow:

<dependency>   <groupId>com.querydsl</groupId>   <artifactId>querydsl-apt</artifactId>   <version>4.0.6</version> </dependency> <dependency>   <groupId>com.querydsl</groupId>   <artifactId>querydsl-jpa</artifactId>   <version>4.0.6</version> </dependency> 

The plugin end up like this:

<plugin>   <groupId>com.mysema.maven</groupId>   <artifactId>apt-maven-plugin</artifactId>   <version>1.1.3</version>   <executions>     <execution>       <phase>generate-sources</phase>       <goals>         <goal>process</goal>       </goals>       <configuration>         <outputDirectory>${project.build.directory}/generated-sources</outputDirectory>          <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>       </configuration>     </execution>   </executions> </plugin> 

I also executed in the command line at the projects root mvn eclipse:eclipse to update Eclipse to include the generated sources.

Update:

Replaced the plugin maven-apt-plugin for apt-maven-plugin and changed version to 1.1.3

like image 130
M.Octavio Avatar answered Sep 26 '22 17:09

M.Octavio