Spring Data Jpa查询DSL Q实体类没有生成 [英] Spring Data Jpa Query DSL Q Entityclasses not generating

查看:775
本文介绍了Spring Data Jpa查询DSL Q实体类没有生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是pom.xml的要点。
我使用的查询dsl版本是 3.6.2

Here's a gist of the pom.xml. The query dsl version I am using is 3.6.2

    <dependency>
        <groupId>com.mysema.querydsl</groupId>
        <artifactId>querydsl-core</artifactId>
    </dependency>
    <dependency>
        <groupId>com.mysema.querydsl</groupId>
        <artifactId>querydsl-apt</artifactId>
    </dependency>
    <dependency>
        <groupId>com.mysema.querydsl</groupId>
        <artifactId>querydsl-jpa</artifactId>
    </dependency>
</dependencies>
<build>
<plugins>
    <plugin>
        <groupId>org.bsc.maven</groupId>
        <artifactId>maven-processor-plugin</artifactId>
        <version>2.2.4</version>
        <configuration>
            <defaultOutputDirectory>
                ${project.build.directory}/generated-sources
            </defaultOutputDirectory>
            <processors>
                <processor>org.mapstruct.ap.MappingProcessor</processor>
            </processors>
        </configuration>
        <executions>
            <execution>
                <id>process</id>
                <phase>generate-sources</phase>
                <goals>
                    <goal>process</goal>
                </goals>
            </execution>
        </executions>
        <dependencies>
            <dependency>
                <groupId>org.mapstruct</groupId>
                <artifactId>mapstruct-processor</artifactId>
                <version>${mapstruct.version}</version>
            </dependency>
        </dependencies>
    </plugin>
    <plugin>
        <groupId>com.mysema.maven</groupId>
        <artifactId>maven-apt-plugin</artifactId>
        <version>1.0.2</version>
        <executions>
            <execution>
                <phase>generate-sources</phase>
                <goals>
                    <goal>process</goal>
                </goals>
                <configuration>
                    <!-- Specifies the directory in which the query types are generated -->
                    <outputDirectory>target/generated-sources/querydsl</outputDirectory>
                    <!-- States that the APT code generator should look for JPA annotations -->
                    <processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>
</build>

每当我运行mvn clean install时,会发生此异常消息

Whenever I run mvn clean install, This exception message occurs

[ERROR] diagnostic: C:\Users\users\app\app-ims\app-ims-core\src\main\java\org\app\genesis\inventory\repo\ProductRepoImpl.java:6: error: cannot find symbol
import org.brightworks.genesis.inventory.model.QProduct;
                                              ^
  symbol:   class QProduct
  location: package org.app.genesis.inventory.model

这是该类的要点。

import com.mysema.query.jpa.impl.JPAQuery;
import com.mysema.query.types.ConstructorExpression;
import org.brightworks.genesis.inventory.dto.ProductDTO;
import org.brightworks.genesis.inventory.model.QProduct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;

import javax.persistence.EntityManager;
import java.util.List;

    /**
     * 
     */
    public class ProductRepoImpl implements ProductRepoCustom {

        @Autowired
        private EntityManager em;

        @Override
        public Page<ProductDTO> search(String term, Pageable pageable) {
            JPAQuery query = new JPAQuery(em);
            QProduct product = QProduct.product;

模型和仓库在同一个项目中,但是没有生成Q实体类。我如何解决这个问题?

The model and the repo are in the same project however the Q Entity classes are not being generated. How do I fix this?

推荐答案

你的mvn apt插件之间存在冲突。你有两个,你只需要一个。只是相应地改变它们。这是一个例子。

There are conflicts between your mvn apt plugins. You have two of them, You only need one. just change them accordingly. Here's an example.

    <plugin>
        <groupId>org.bsc.maven</groupId>
        <artifactId>maven-processor-plugin</artifactId>
        <version>2.2.4</version>
        <configuration>
            <defaultOutputDirectory>
                ${project.build.directory}/generated-sources
            </defaultOutputDirectory>
            <processors>
                <processor>org.mapstruct.ap.MappingProcessor</processor>
                <processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
            </processors>
        </configuration>
        <executions>
            <execution>
                <id>process</id>
                <phase>generate-sources</phase>
                <goals>
                    <goal>process</goal>
                </goals>
            </execution>
        </executions>
        <dependencies>
            <dependency>
                <groupId>org.mapstruct</groupId>
                <artifactId>mapstruct-processor</artifactId>
                <version>${mapstruct.version}</version>
            </dependency>
        </dependencies>
    </plugin>

这篇关于Spring Data Jpa查询DSL Q实体类没有生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆