Harshal Patil
Harshal Patil

Reputation: 357

Spring data Querydsl in eclipse not generating query type classes

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

Answers (4)

Pradeep Kumar S
Pradeep Kumar S

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

elpair
elpair

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:

  1. rightclick a project and select properties
  2. in the properties navigate to Maven -> Annotation Processing
  3. to enable this option for the whole workspace and not just for this specific module select Configure Workspace Settingsenter image description here
  4. Select Experimental: Delegate annotation processing to maven plugins (for maven processor only).enter image description here
  5. Click Apply.

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

Harshal Patil
Harshal Patil

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

Patrick
Patrick

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

Related Questions