3

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>

`

2
  • 1
    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. Commented Apr 24, 2018 at 6:21
  • Thanks source are generated in the target folder Commented Apr 24, 2018 at 8:46

4 Answers 4

5

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.
Sign up to request clarification or add additional context in comments.

1 Comment

Ohh nice help!! with a maven command-line will be: mvn clean compile.
1

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.

Comments

1

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>

Comments

-1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.