0

我有一个@Entity使用querydsl代码生成的类。

问题:我的实体有一个包含一些@Transient字段的父实体。这些在生成过程中不会被跳过。

package com.domain.myentity

@Entity
public class MyEntity extends AuditingEntity {

}


package com.auditing

@MappedSuperclass
public class AuditingEntity {
    @Transient
    private transient Object obj;
}

包信息.java:

@QueryEntities(value = MyEntity.class)
package com.domain.myentity

import com.querydsl.core.annotations.QueryEntities;
import com.domain.myentity.MyEntity;

问题:如何告诉 querydsl@Transient自动忽略任何字段?目前,根本原因可能是AuditingEntity与域实体位于不同的文件夹中,因此未在package-info.javaquerydsl 中列出。但是我怎么能在不移动审计实体的情况下解决它呢?

期间产生:

<plugin>
    <groupId>com.mysema.maven</groupId>
    <artifactId>apt-maven-plugin</artifactId>
    <version>${apt-maven-plugin.version}</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>
    <dependencies>
        <dependency>
            <groupId>com.querydsl</groupId>
            <artifactId>querydsl-apt</artifactId>
            <version>${querydsl.version}</version>
        </dependency>
    </dependencies>
</plugin>
4

2 回答 2

2

If you want to prevent QueryDsl from mapping a field or method you should use the @QueryType - annotation with PropertyType.NONE.

The value PropertyType.NONE can be used to skip a property in the query type generation. This case is different from @Transient or @QueryTransient annotated properties, where properties are not persisted. PropertyType.NONE just omits the property from the Querydsl query type.

@Entity
public class MyEntity {


    @QueryType(PropertyType.NONE)
    public String stringNotInQuerydsl;

}

See the official documentation here

于 2019-11-05T14:31:43.637 回答
1

你可以尝试瞬态声明transient String obj; 而不是

@Transient
private Object obj;
于 2019-05-03T00:14:32.210 回答