简体   繁体   English

带neo4j partial = true和jpa瞬变的querydsl Q *类生成

[英]querydsl Q* class generation with neo4j partial=true and jpa transient

i have this simple entity 我有这个简单的实体

@Entity(name = "person")
@NodeEntity(partial = true)
public class Person {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private Long id;

    @Transient
    @GraphProperty
    private String sureName;

    @QueryTransient
    @Column(name = "surename")
    private String firstName;
}

now i try to create with the querydsl apt-maven-plugin to generate the Q* classes. 现在,我尝试使用querydsl apt-maven-plugin创建以生成Q *类。 in my pom.xml i have this configuration: 在我的pom.xml中,我有以下配置:

<plugin>
    <groupId>com.mysema.maven</groupId>
    <artifactId>apt-maven-plugin</artifactId>
    <version>1.1.1</version>
    <executions>
        <execution>
            <goals>
                <goal>process</goal>
            </goals>
            <configuration>
                <outputDirectory>target/generated-sources/java</outputDirectory>
                <processors> 
                   <processor>org.springframework.data.neo4j.querydsl.SDNAnnotationProcessor</processor>    
                   <processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
                </processors>
            </configuration>
        </execution>
    </executions>
</plugin>

the problem now is that the last processor overwrite the first generated class with the new one. 现在的问题是最后一个处理器用新的覆盖了第一个生成的类。 The idea was to have separate Q* clases for neo4j and for JPA because of the transient fields. 想法是由于瞬变场而使neo4j和JPA具有单独的Q *分类。 The results with only one processor: 仅使用一个处理器的结果:

SDNAnnotationProcessor SDNAnnotationProcessor

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

    private static final long serialVersionUID = 1610526870L;

    public static final QPerson person = new QPerson("person");

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

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

    public QPerson(String variable) {
        super(Person.class, forVariable(variable));
    }

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

    public QPerson(PathMetadata<?> metadata) {
        super(Person.class, metadata);
    }

}

JPAAnnotationProcessor JPAAnnotationProcessor

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

    private static final long serialVersionUID = 1610526870L;

    public static final QPerson person = new QPerson("person");

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

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

    public QPerson(String variable) {
        super(Person.class, forVariable(variable));
    }

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

    public QPerson(PathMetadata<?> metadata) {
        super(Person.class, metadata);
    }

}

does anybody know how to separate these generated classes? 有谁知道如何分离这些生成的类?

You will need to use two executions for this 为此,您将需要使用两次执行

<plugin>
    <groupId>com.mysema.maven</groupId>
    <artifactId>apt-maven-plugin</artifactId>
    <version>1.1.1</version>
    <executions>
        <execution>
            <goals>
                <goal>process</goal>
            </goals>
            <configuration>
                <outputDirectory>target/generated-sources/jpa</outputDirectory>
                <processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
            </configuration>
        </execution>
        <execution>
            <goals>
                <goal>process</goal>
            </goals>
            <configuration>
                <outputDirectory>target/generated-sources/neo4j</outputDirectory>                <processor>org.springframework.data.neo4j.querydsl.SDNAnnotationProcessor</processor>
                <options>
                    <querydsl.prefix>N</querydsl.prefix>
                </options>  
            </configuration>
        </execution>
    </executions>
</plugin>

The second execution uses N as the class name prefix instead of default Q. Feel free to shape this for your needs. 第二次执行使用N作为类名前缀而不是默认Q。可以根据需要随意调整形状。

Reference http://www.querydsl.com/static/querydsl/3.3.2/reference/html/ch03s03.html 参考http://www.querydsl.com/static/querydsl/3.3.2/reference/html/ch03s03.html

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

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