【问题标题】:Recreation of entity classes实体类的重新创建
【发布时间】:2014-11-28 14:32:10
【问题描述】:

我尝试在 netbeans 8.0.1 上运行带有 hibernate、spring 和 jpa 的 Web 应用程序,但现在我在编译应用程序时遇到了这个异常......这是以下错误:

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-    compile) on project SMSXxxxx: Compilation failure: Compilation failure:
error: Problem with Filer: Attempt to recreate a file for type  com.equitel.smsmanager.entities.TextMessageContent_
error: Problem with Filer: Attempt to recreate a file for type com.smsmanager.entities.SmsUser_

这里是持久化单元,我的项目中只有一个

<?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="SMSManagerPU" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/jboss/datasources/SMSManagerDS</jta-data-source>
<class>com.smsmanager.entities.Approval</class>
<class>com.smsmanager.entities.Changelog</class>
<class>com.smsmanager.entities.Contacts</class>
<class>com.smsmanager.entities.Dispatches</class>
<class>com.smsmanager.entities.MessageSchedule</class>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
  <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
</properties>
</persistence-unit>
</persistence>

我还没有解决这个错误,你能帮我解决这个问题吗?

【问题讨论】:

  • 你介意给我们看一下 pom.xml 文件吗?
  • 在eclipse中能用吗???
  • 6年多过去了,这个问题有解决办法吗?

标签: jpa


【解决方案1】:

由于某些原因,pom.xml 中有一个依赖项,在我的情况下导致了问题。查找并删除它:

    <dependency>
        <groupId>unknown.binary</groupId>
        <artifactId>hibernate-jpamodelgen-4.3.1.Final</artifactId>
        <version>SNAPSHOT</version>
        <scope>provided</scope>
    </dependency>

这可能是 Netbeans 中的一个错误。 https://netbeans.org/bugzilla/show_bug.cgi?id=183779

【讨论】:

  • 移除该依赖可能会导致其他问题,例如不再生成 jpa 元模型。
【解决方案2】:

检查您的 pom.xml 文件 maven-compiler-plugin 是否添加。如果没有,请添加插件,如下所示。

<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>              
</plugin>

您可以通过在 cmd 提示符下使用 mvn clean install -X 来查找根本原因。

检查您的pom.xml 文件中提到的java 版本,并检查$JAVA_HOME 中提到的java 版本 环境变量。两者应该是一样的。

也检查一下

  • 可能是它的 Java 编译器问题。
  • 下载 jar 可能有问题

【讨论】:

    【解决方案3】:

    对我有用的解决方案: 尝试删除:

    <dependency>
        <groupId>unknown.binary</groupId>
        <artifactId>hibernate-jpamodelgen-4.3.1.Final</artifactId>
        <version>SNAPSHOT</version>
        <scope>provided</scope>
    </dependency>
    

    然后添加一个带有激活和依赖的maven配置文件

    <profiles>
    <profile>
        <id>profile-JPA-Gen</id>
        <activation>
            <property>
                <name>activate_gen</name>
                <value>true</value>
            </property>
        </activation>
        <dependency>
            <groupId>unknown.binary</groupId>
            <artifactId>hibernate-jpamodelgen</artifactId>
            <version>SNAPSHOT</version>
        </dependency>
    </profile> </profiles>
    

    运行一次mvn install -P profile-JPA-Gen只生成相关类,然后使用mvn clean install

    【讨论】:

      猜你喜欢
      • 2012-03-28
      • 1970-01-01
      • 1970-01-01
      • 2013-05-06
      • 1970-01-01
      • 1970-01-01
      • 2018-03-07
      • 1970-01-01
      相关资源
      最近更新 更多