gpt4 book ai didi

hibernate - Maven Aspectj插件再次调用JPA模型生成器

转载 作者:行者123 更新时间:2023-12-03 06:42:22 26 4
gpt4 key购买 nike

我有一个 Maven 项目,在其中使用 Hibernate 元模型生成器生成 JPA 元模型。

<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>
<parent>
<groupId>xxx</groupId>
<artifactId>xxx</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>xxx</artifactId>
<dependencies>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>

<dependency>
<!-- needed for meta model generation (see also compiler plugin config) -->
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>4.3.8.Final</version>
</dependency>
</dependencies>
</project>

AspectJ 编译器在父项目中配置。当我运行 Maven 时,首先调用 Java 编译器插件并正确生成目标/生成源/生成源/注释的源。然后执行 AspectJ 插件,再次生成源代码,现在进入我项目的根文件夹并抛出以下错误:

D:\xxx\git\xxx>mvn clean install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building xxx 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ xxx ---
[INFO] Deleting D:\...
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ xxx ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO]
[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ xxx ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 63 source files to D:\xxx\git\xxx\target\classes
[INFO]
[INFO] --- aspectj-maven-plugin:1.7:compile (default) @ xxx ---
[INFO] Showing AJC message detail for messages of types: [error, warning, fail]
[WARNING] Hibernate JPA 2 Static-Metamodel Generator 4.3.8.Final
<unknown source file>:<no line information>

[ERROR] The type Category_ is already defined
D:\xxx\git\xxx\Category_.java:10
public abstract class Category_ extends com.xxx.AbstractEntity_ {
^^^^^^^^

[ERROR] The type Attachment_Message_ is already defined
D:\xxx\git\xxx\Attachment_Message_.java:9
public abstract class Attachment_Message_ extends com.xxx.AbstractEntity_ {
^^^^^^^^^^^^^^^^^^

[ERROR] The type AbstractNamedEntity_ is already defined
D:\xxx\git\xxx\AbstractNamedEntity_.java:9
public abstract class AbstractNamedEntity_ extends com.xxx.AbstractEntity_ {

...

如何阻止 AspectJ 编译器再次执行模型生成器?

最佳答案

重点是AspectJ 1.8.2 is the fist version that include the Annotation Processing Feature这导致了生成。

有两种方法可以禁用生成:

  • 1)升级Maven-AspectJ-Plugin版本1.8,它有一个新参数:proc,将其设置为none以禁用生成。请参阅GitHub Issue #5 ,

    <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.8</version>
    ...
    <configuration>
    ...
    <proc>none</proc>
    </configuration>
    </plugin>

  • 2) 另一种“解决方案”是使用 AspectJ 版本 1.8.1,而不是 1.8.2+。

关于hibernate - Maven Aspectj插件再次调用JPA模型生成器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28022190/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com