Reputation: 357
I don't see query dsl classes generated in eclipse added below dependency and plugin in the pom.xml. Can some please review below change required for query-dsl integration in spring boot?
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>${querydsl.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>${querydsl.version}</version>
</dependency>
<!--Plugin for query-dsl -->
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
`
Upvotes: 3
Views: 3398
Reputation: 11
The dependencies you added are correct.It generates Q types for classes annotated with @Entity.This annotation is from package jakarta.persistence in later versions. It does not recognizes this as entities. Only @Entity from package javax.persistence is recognized by querydsl(5.0.0). Use older versions of spring data jpa. But that is not an ideal solution. Better way to solve this is by altering processor of your plugin and add @QueryEntity annotation in your entities. here's the code.
<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>target/generated-sources/java</outputDirectory>
<processor>com.querydsl.apt.QuerydslAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
Upvotes: 1
Reputation: 106
This problem is due to annotation processing of M2E. New Eclipse versions contain an experimental feature, which delegates annotation processing to maven plugins and thus behaves the same as using mvn from the command line.
To enable the feature:
Maven -> Annotation Processing
Configure Workspace Settings
Experimental: Delegate annotation processing to maven plugins (for maven processor only)
.This way Eclipse processes annotations with the plugins defined in the pom.xml
. Resources are now generated when building the project and also found as dependency. No need to build the project manually with maven.
Upvotes: 1
Reputation: 357
I followed below 2 steps after that Query dsl class stopped giving compilation error.
Enable annotation processing in eclipse. Add generated package in source in the classpath.
Upvotes: -1
Reputation: 12734
In eclipse, sometimes you have to refresh your project multiple times to see the generated-sources. If not try to generate the files by
right click on your project -> run as -> maven generate sources.
Upvotes: 4