JavaQueryDsl代码生成不生成Qclass
Java QueryDsl code generation does not generate Q class
我正在制作一个 Spring 项目,我在其中为实体使用 QueryDsl。我从几个月前开始接手这个项目,在那里我已经生成了 1 个 class (QUser)。现在我创建了一个名为 Permission 的新实体,并修改了 User 实体。当我构建项目时,QUser 没有改变,QPermission class 也没有生成。我究竟做错了什么?这是 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;
}
}
和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>
[...]
我正在关注文档:
http://www.querydsl.com/static/querydsl/3.2.0/reference/html/ch03s03.html
我正在使用 IntellIJ IDEA 并尝试了 "Rebuild project" 选项。
这是一个有效的 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>
和生成的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);
}
}
你能展示你在 pom.xml 中的依赖关系吗?
我从头开始做了一些测试
这里是依赖项:
<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>
和插件:
<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>
我尝试生成 QFiles 的完整源代码并且有效:
https://github.com/githubjul/test-so-querydsl
我没有运行这个项目,只是编译它以验证它是否有效。
添加以下依赖项对我有用:
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>3.7.4</version>
</dependency>
您可以在这里查看最新版本:
https://mvnrepository.com/artifact/com.mysema.querydsl/querydsl-jpa
我在使用 IntelliJ 时遇到了这个问题。
以下步骤对我有用:
- 右键单击我的 POM,
- 点击了 'Maven'、
- 点击了 'reload project'。
这似乎可以解决问题。
我正在制作一个 Spring 项目,我在其中为实体使用 QueryDsl。我从几个月前开始接手这个项目,在那里我已经生成了 1 个 class (QUser)。现在我创建了一个名为 Permission 的新实体,并修改了 User 实体。当我构建项目时,QUser 没有改变,QPermission class 也没有生成。我究竟做错了什么?这是 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;
}
}
和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>
[...]
我正在关注文档: http://www.querydsl.com/static/querydsl/3.2.0/reference/html/ch03s03.html 我正在使用 IntellIJ IDEA 并尝试了 "Rebuild project" 选项。
这是一个有效的 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>
和生成的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);
}
}
你能展示你在 pom.xml 中的依赖关系吗?
我从头开始做了一些测试
这里是依赖项:
<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>
和插件:
<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>
我尝试生成 QFiles 的完整源代码并且有效:
https://github.com/githubjul/test-so-querydsl
我没有运行这个项目,只是编译它以验证它是否有效。
添加以下依赖项对我有用:
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>3.7.4</version>
</dependency>
您可以在这里查看最新版本:
https://mvnrepository.com/artifact/com.mysema.querydsl/querydsl-jpa
我在使用 IntelliJ 时遇到了这个问题。
以下步骤对我有用:
- 右键单击我的 POM,
- 点击了 'Maven'、
- 点击了 'reload project'。
这似乎可以解决问题。