You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行hibernate-tools-maven-plugin报错:元素hibernate-reverse-engineering未声明

问题

运行mvn clean install时,执行hibernate-tools-maven-plugin的hbm2java目标失败,报错信息如下:

Could not configure overrides from file: ... invalid override definition: Element type "hibernate-reverse-engineering" must be declared

但reveng.xml文件中已包含<hibernate-reverse-engineering>元素,相关配置文件如下:

pom.xml配置

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>Test</groupId>
  <artifactId>Hibernate_Reveng_Maven</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>Hibernate Reveng Gen Java</name>
  
  <properties>
      <project.basedir>C:/Kei/SLIS_git_eclipse_2023_09_20231115_2/Hibernate_Reveng (Not work) </project.basedir>
    <h2.version>1.4.200</h2.version>   
    
  </properties>
  
  <build>
      <plugins>
        <plugin>           
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-tools-maven-plugin</artifactId>
            <version>5.4.29.Final</version>         
            <executions>
                  <execution>
                    <id>entity-generation</id>
                    <phase>generate-sources</phase>
                    <goals>
                      <goal>hbm2java</goal>
                    </goals>
                    <configuration>
                      <ejb3>true</ejb3>
                      <revengFile>${project.basedir}/src/main/resources/reveng.xml</revengFile>
                    </configuration>
                  </execution>                
        </executions>   
        <dependencies>
            <dependency>
                <groupId>com.oracle.database.jdbc</groupId>
                <artifactId>ojdbc8</artifactId>
                <version>12.2.0.1</version>
            </dependency>
        </dependencies>     
      </plugin>      
      </plugins>
    </build>
    
    <dependencies>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-tools-maven-plugin</artifactId>
            <version>5.4.29.Final</version>
        </dependency>           
            <!-- https://mvnrepository.com/artifact/com.oracle/ojdbc14 -->
         <dependency>
            <groupId>com.oracle.database.jdbc</groupId>
            <artifactId>ojdbc8</artifactId>
            <version>12.2.0.1</version>
        </dependency>
    </dependencies>
</project>

hibernate.properties配置

hibernate.dialect=org.hibernate.dialect.Oracle12cDialect
#hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver
hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver
hibernate.connection.url=jdbc:oracle:thin:@10.9.xxx.xx:25100:dsli01.xxxxx.com
hibernate.connection.username=dsli01
hibernate.connection.password=xxxxxx

reveng.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC 
  "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" 
  "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >

<hibernate-reverse-engineering>
  <!-- This assumes your database connection is pointing to the proper catalog -->
  <!-- To get all tables in the named schema, use the following 
       <schema-selection match-schema="PM" />
  -->
  <!--  to get only the named tables -->
  <schema-selection match-schema="dsli01" match-table="UAC_USER_SSN"/>
  
</hibernate-reverse-engineering>

疑问

该错误是什么意思?为何已包含对应元素仍报错?

解答

错误含义

这个错误说明Hibernate工具解析reveng.xml时,无法找到<hibernate-reverse-engineering>元素的定义,本质是XML验证环节失败,通常和DTD文件加载异常、版本不匹配有关。

报错原因及解决办法

  1. DTD远程地址无法访问
    你使用的DTD地址http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd可能因网络问题或地址失效无法加载,导致XML解析器无法识别元素定义。

    • 解决:下载对应DTD文件到本地(可从hibernate-tools的jar包中提取,路径为org/hibernate/tool/reveng/resources/hibernate-reverse-engineering-3.0.dtd),修改reveng.xml的DOCTYPE引用为本地路径:
      <!DOCTYPE hibernate-reverse-engineering PUBLIC 
        "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" 
        "classpath:/hibernate-reverse-engineering-3.0.dtd" >
      
  2. 路径含空格导致文件读取失败
    pom.xml中project.basedir的路径包含空格(Hibernate_Reveng (Not work)),可能导致插件无法正确定位reveng.xml文件,进而解析出错。

    • 解决:要么修改项目路径移除空格,要么改用相对路径配置revengFile:
      <revengFile>src/main/resources/reveng.xml</revengFile>
      
  3. 依赖冗余引发冲突
    pom.xml同时在全局<dependencies>和插件内部<dependencies>中引入了hibernate-tools-maven-plugin,可能导致版本冲突或加载异常。

    • 解决:删除全局<dependencies>块中的hibernate-tools-maven-plugin依赖,仅保留插件内部的依赖配置。
  4. 版本不匹配
    若DTD版本与使用的hibernate-tools-maven-plugin版本不兼容,也会出现元素未定义的错误。

    • 解决:确保DTD版本与插件版本对应,优先使用插件内置的DTD引用方式(如classpath路径)避免手动指定远程地址。

内容的提问来源于stack exchange,提问作者user1169587

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 05:55:12