apt-maven-plugin不为带有@Entity表示法的实体生成QClass

时间:2019-04-17 16:50:26

标签: java spring-boot jpa querydsl

希望你很好。

这是问题,我正在尝试将dslQuery与spring-boot结合使用,以便立即进行高级搜索,但是maven插件不会为实体生成TClass。

pom.xml

<project ...>
    ...

    <properties>
        <!-- General -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>

        <!-- Plugins -->
        <com.mysema.maven.apt-maven-plugin.version>1.1.3</com.mysema.maven.apt-maven-plugin.version>

        <!-- Dependencies -->
        <com.querydsl.version>4.2.1</com.querydsl.version>

        <org.springframework.boot.version>2.1.4.RELEASE</org.springframework.boot.version>

        <org.hibernate.javax.persistence.version>1.0.1.Final</org.hibernate.javax.persistence.version>
        <org.hibernate.hibernate-core.version>5.4.1.Final</org.hibernate.hibernate-core.version>

        <org.junit.platform.junit-platform-surefire-provider.version>1.0.1
        </org.junit.platform.junit-platform-surefire-provider.version>
    </properties>

    <build>
        ...

        <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>${org.apache.maven.plugins.maven-compiler-plugin.version}</version>
                    <configuration>
                        <source>${maven.compiler.source}</source>
                        <target>${maven.compiler.target}</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>com.mysema.maven</groupId>
                    <artifactId>apt-maven-plugin</artifactId>
                    <version>${com.mysema.maven.apt-maven-plugin.version}</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>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <version>${org.springframework.boot.version}</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <dependencies>
        ...

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

        <!-- Spring -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <version>${org.springframework.boot.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <version>${org.springframework.boot.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>${org.springframework.boot.version}</version>
            <scope>compile</scope>
        </dependency>

        <!-- Persistence -->
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>${org.hibernate.javax.persistence.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${org.hibernate.hibernate-core.version}</version>
        </dependency>
    </dependencies>
</project>

示例实体:

package com.expenses.core.expense.entities;

import com.expenses.core.common.entities.AbstractEntity;
import com.expenses.core.utils.Copyable;

import javax.annotation.Nonnull;
import javax.persistence.*;
import java.util.Objects;

@Entity(name = "Account")
@Table(name = "account")
@SequenceGenerator(name = "account_generator", sequenceName = "account_id_seq", allocationSize = 1)
public class Account extends AbstractEntity<Account> implements Copyable<Account> {

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "account_generator")
    @Column(name = "id")
    private Long id;

    private final String cbu;

    private final String alias;

    private final String bank;

    private final String description;

}

我知道论坛和Google中都有类似的帖子,但是尝试这些帖子中的内容之后,问题仍然存在。

关于如何解决此问题的任何想法?

PS:AccountRepository确实从JpaRepository<Account, Long>QuerydslPredicateExecutor<Account>扩展。

1 个答案:

答案 0 :(得分:0)

我仍然不知道插件配置出了什么问题,但是我碰到了这一点,并且成功了(从pom中删除了插件之后)。 希望对别人有帮助

package test2;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class Test2 {
    private static void createAndShowGUI() {
        JFrame frame = new JFrame("Test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        CustomerData customerData = new CustomerData("Testing a long observation text that should wrap only when reaching the observation limit.");
        new JDViewCustomer(frame, true, customerData).setVisible(true);

        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}

PS:我很想知道为什么我的旧配置无法正常工作。