【问题标题】:How to generate JPA Hibernate Metamodel classes in IntelliJ IDEA?如何在 IntelliJ IDEA 中生成 JPA Hibernate 元模型类?
【发布时间】:2020-03-06 17:24:41
【问题描述】:

我正在尝试在 IntelliJ 理念中使用 Hibernate 生成元模型类。 我已经看过最古老的教程,但它们对我没有帮助。 还有其他方法可以生成该文件吗?我在 IntelliJ 中发现的有关 Metamodel 支持的主题太老了。 也许我做错了什么。我会解释我在做什么。

我已经试过了:

  • 在 IntelliJ 设置中启用处理:设置 > 构建、执行、部署 > 编译器 > 注释处理器 > [检查] 启用注释处理。

  • 将 maven 处理器放在 pom.xml 中。 (jpa.modelgen.CanonicalModelProcessor)

  • 重建项目。

我在 pom.xml 中包含的插件:

<plugin>
                <groupId>org.bsc.maven</groupId>
                <artifactId>maven-processor-plugin</artifactId>
                <version>1.3.5</version>
                <executions>
                    <execution>
                        <id>process</id>
                        <goals>
                            <goal>process</goal>
                        </goals>
                        <phase>generate-sources</phase>
                        <configuration>
                            <outputDirectory>${project.build.directory}/generated-sources/metamodel</outputDirectory>
                            <compilerArguments>
                                -Aeclipselink.persistencexml=${project.basedir}/src/main/resources/META-INF/persistence.xml
                            </compilerArguments>
                            <processors>
                                <processor>org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor
                                </processor>
                            </processors>
                        </configuration>
                    </execution>
                </executions>
</plugin>

【问题讨论】:

  • 通过该配置并重建项目,我的src/main/java 文件夹变为空!我的target 文件夹中出现了一个“生成”文件夹。

标签: java hibernate intellij-idea


【解决方案1】:

在项目的 pom.xml 中添加以下依赖。

<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-jpamodelgen -->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-jpamodelgen</artifactId>
        <version>5.3.7.Final</version>
        <scope>provided</scope>

    </dependency>

然后在模块/项目的构建路径上使用..path_to_root_directory_of_module_of_entities/target/classes/ 目录。 它将使所有自动生成的静态模型类对项目的运行时可用。

【讨论】:

    猜你喜欢
    • 2021-12-22
    • 2017-11-27
    • 1970-01-01
    • 2013-01-21
    • 2021-08-30
    • 2018-09-24
    • 1970-01-01
    • 1970-01-01
    • 2011-03-03
    相关资源
    最近更新 更多