简体   繁体   English

Java QueryDsl代码生成不生成Q类

[英]Java QueryDsl code generation does not generate Q class

I'm making a Spring project, where i'm using QueryDsl for the entities.我正在制作一个 Spring 项目,我在其中使用 QueryDsl 作为实体。 I'm picking up this project from a few months back, where i already had 1 generated class (QUser).我从几个月前开始着手这个项目,在那里我已经有了 1 个生成的类 (QUser)。 Now i made a new entity called Permission, and modified the User entity.现在我创建了一个名为 Permission 的新实体,并修改了 User 实体。 When i'm building the project, the QUser doesn't change, and the QPermission class is not generating either.当我构建项目时, QUser 不会更改,并且 QPermission 类也不会生成。 What am i doing wrong?我究竟做错了什么? Here's the entity and pom.xml for QueryDsl.这是 QueryDsl 的实体和 pom.xml。

@Entity
@Table(name = "permission")
public class Permission {
   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   private Long id;

   @Column(name = "name", length = 100, nullable = false)
   private String name;


   public Long getId() {
       return id;
   }

   public void setId(Long id) {
       this.id = id;
  }

    public String getName() {
       return name;
   }
    public void setName(String name) {
        this.name = name;
    }
}

And the pom.xml:和 pom.xml:

[..]
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <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.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
[...]

I was following the documentation: http://www.querydsl.com/static/querydsl/3.2.0/reference/html/ch03s03.html I'm using IntellIJ IDEA and tried the "Rebuild project" option as well.我正在关注文档: http ://www.querydsl.com/static/querydsl/3.2.0/reference/html/ch03s03.html 我正在使用 IntellIJ IDEA 并尝试了“重建项目”选项。

Can you show the dependencies you put in your pom.xml ?你能显示你放在 pom.xml 中的依赖项吗?

I've made some tests starting from scratch我从头开始做了一些测试

Here are the dependencies :以下是依赖项:

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

And the plugin :和插件:

        <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>

The complete source code I've tried to generate QFiles and that worked :我尝试生成 QFiles 的完整源代码有效:

https://github.com/githubjul/test-so-querydsl https://github.com/githubjul/test-so-querydsl

I don't run the project, only compile it to verify it works.我不运行该项目,只编译它以验证它是否有效。

Here is a working pom.xml这是一个工作pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.hello</groupId>
    <artifactId>querydsl</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>querydsl</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <querydsl.version>4.1.0</querydsl.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.querydsl</groupId>
            <artifactId>querydsl-apt</artifactId>
            <version>${querydsl.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.querydsl</groupId>
            <artifactId>querydsl-jpa</artifactId>
            <version>${querydsl.version}</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.hibernate.javax.persistence/hibernate-jpa-2.0-api -->
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>1.0.1.Final</version>
        </dependency>


        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.6.1</version>
        </dependency>
    </dependencies>


    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <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</outputDirectory>
                            <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

and the generated class:和生成的类:

/**
 * QPermission is a Querydsl query type for Permission
 */
@Generated("com.querydsl.codegen.EntitySerializer")
public class QPermission extends EntityPathBase<Permission> {

    private static final long serialVersionUID = -479242270L;

    public static final QPermission permission = new QPermission("permission");

    public final NumberPath<Long> id = createNumber("id", Long.class);

    public final StringPath name = createString("name");

    public QPermission(String variable) {
        super(Permission.class, forVariable(variable));
    }

    public QPermission(Path<? extends Permission> path) {
        super(path.getType(), path.getMetadata());
    }

    public QPermission(PathMetadata metadata) {
        super(Permission.class, metadata);
    }

}

Adding the following dependency did it for me:添加以下依赖项对我有用:

<dependency>
    <groupId>com.mysema.querydsl</groupId>
    <artifactId>querydsl-jpa</artifactId>
    <version>3.7.4</version>
</dependency>

You can look up the latest version here:您可以在此处查找最新版本:

https://mvnrepository.com/artifact/com.mysema.querydsl/querydsl-jpa https://mvnrepository.com/artifact/com.mysema.querydsl/querydsl-jpa

I was having this issue using IntelliJ.我在使用 IntelliJ 时遇到了这个问题。

The following steps worked for me:以下步骤对我有用:

  1. Right-clicked my POM,右键单击我的 POM,
  2. Clicked 'Maven',点击“Maven”,
  3. Clicked 'reload project'.单击“重新加载项目”。

This seemed to do the trick.这似乎奏效了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM