gpt4 book ai didi

java - JPA:错误:尝试重新创建类型 的文件

转载 作者:太空宇宙 更新时间:2023-11-04 09:40:41 36 4
gpt4 key购买 nike

每次运行代码时,都会收到以下错误:

 java.lang.RuntimeException: javax.annotation.processing.FilerException: Attempt to recreate a file for type domein.ClubLes_
[javac] at org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor.process(CanonicalModelProcessor.java:407)
[javac] at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:964)
[javac] at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:881)
[javac] at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.access$2100(JavacProcessingEnvironment.java:110)
[javac] at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1202)
[javac] at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1311)
[javac] at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1250)
[javac] at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:928)
[javac] at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:306)
[javac] at jdk.compiler/com.sun.tools.javac.main.Main.compile(Main.java:165)
[javac] at jdk.compiler/com.sun.tools.javac.Main.compile(Main.java:57)
[javac] at jdk.compiler/com.sun.tools.javac.Main.main(Main.java:43)
[javac] Caused by: javax.annotation.processing.FilerException: Attempt to recreate a file for type domein.ClubLes_
[javac] at jdk.compiler/com.sun.tools.javac.processing.JavacFiler.checkNameAndExistence(JavacFiler.java:727)
[javac] at jdk.compiler/com.sun.tools.javac.processing.JavacFiler.createSourceOrClassFile(JavacFiler.java:489)
[javac] at jdk.compiler/com.sun.tools.javac.processing.JavacFiler.createSourceFile(JavacFiler.java:426)
[javac] at org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor.generateCanonicalModelClass(CanonicalModelProcessor.java:98)
[javac] at org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor.generateCanonicalModelClasses(CanonicalModelProcessor.java:226)
[javac] at org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor.process(CanonicalModelProcessor.java:403)
[javac] ... 11 more

BUILD FAILED
E:\ProjectJava\java-g11\Taijitan\nbproject\build-impl.xml:1134: The following error occurred while executing this line:
E:\ProjectJava\java-g11\Taijitan\nbproject\build-impl.xml:381: Compile failed; see the compiler error output for details.

起初我以为这是因为我不小心忘记添加子类,但它仍然给我同样的错误。 ClubLes 继承自 Les,Les 是一个仅包含 getter 的接口(interface)。我还需要使接口(interface)可序列化吗?我不知道出了什么问题。

俱乐部

@Entity
public class ClubLes implements Serializable, Les {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "LesId")
private int id;
@Column(name = "Naam")
String naam;
@Column(name = "Soort")
String soort;
@ManyToOne
@JoinColumn(name = "GraadNumeriek")
Graad graad;
@Column(name = "FotoUrl")
private String fotoUrl;
@Column(name = "Beschrijving")
private String beschrijving;
@Column(name = "VideoUrl")
private String videoUrl;

public ClubLes() {
}

Les界面

public interface Les {

int getId();
String getNaam();
String getSoort();
//More getters
}

PU
我只有一个持久性单元,如下所示

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="TaijitanPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>domein.Graad</class>
<class>domein.Locatie</class>
<class>domein.ClubPersoon</class>
<class>domein.ClubActiviteit</class>
<class>domein.ClubLes</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:sqlserver://localhost:1433;databaseName=Taijitan"/>
<property name="javax.persistence.jdbc.user" value="sa"/>
<property name="javax.persistence.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<property name="javax.persistence.jdbc.password" value="Wachtwoord2019"/>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
</properties>
</persistence-unit>
</persistence>

我还注意到,当我从 JPA 中删除 Clublesson 时,它会为 ClubPerson 抛出相同的错误,它遵循相同的方案

最佳答案

我也遇到了这个错误,这是因为我在 pom.xml 中有依赖项和元模型插件配置,所以它们被生成了两次。尝试删除其中之一。

我的依赖配置:

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<scope>provided</scope>
</dependency>

我的插件配置:

<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>4.5</version>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<!-- source output directory -->
<outputDirectory>target/metamodel</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/metamodel</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>

关于java - JPA:错误:尝试重新创建类型 <MyClass> 的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56020334/

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