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

执行mvn hibernate3:hbm2java时找不到org.hibernate.engine.Mapping类

解决执行 mvn hibernate3:hbm2java 时的 NoClassDefFoundError: org/hibernate/engine/Mapping 错误

问题根源

你使用的 org.codehaus.mojo:hibernate3-maven-plugin:3.0 是针对 Hibernate 3 设计的过时插件,与 Hibernate 4+ 及 JDK 11 不兼容。org.hibernate.engine.Mapping 是 Hibernate 3 的内部类,在 Hibernate 4+ 版本中已被重构或移除,导致插件无法找到该类。

解决方案

替换为官方维护的 hibernate-tools-maven-plugin,该插件支持新版本 Hibernate 和 JDK 11,同时调整依赖至兼容的 Hibernate 版本。

修正后的插件配置

<plugin>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-tools-maven-plugin</artifactId>
    <version>5.6.14.Final</version>
    <executions>
        <execution>
            <id>generate-entities</id>
            <phase>post-clean</phase>
            <goals>
                <goal>hbm2java</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <basePackage>com.cm.sourcegenerator</basePackage>
        <revengFile>src/main/resources/hibernate/hibernate.reveng.xml</revengFile>
        <outputDirectory>${project.build.sourceDirectory}</outputDirectory>
        <jdbcConnection>
            <!-- 补充你的数据库连接信息 -->
            <driverClass>com.mysql.cj.jdbc.Driver</driverClass>
            <url>jdbc:mysql://localhost:3306/your_database?useSSL=false&amp;serverTimezone=UTC</url>
            <username>your_username</username>
            <password>your_password</password>
        </jdbcConnection>
        <hibernateTemplate>
            <property name="hibernate.dialect">org.hibernate.dialect.MySQL8Dialect</property>
        </hibernateTemplate>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <version>8.0.33</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.6.14.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-tools</artifactId>
            <version>5.6.14.Final</version>
        </dependency>
        <!-- JDK 11 所需的 JAXB 依赖 -->
        <dependency>
            <groupId>jakarta.xml.bind</groupId>
            <artifactId>jakarta.xml.bind-api</artifactId>
            <version>2.3.3</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jaxb</groupId>
            <artifactId>jaxb-runtime</artifactId>
            <version>2.3.3</version>
        </dependency>
    </dependencies>
</plugin>

关键说明

  • 新插件使用 org.hibernate:hibernate-tools-maven-plugin,替代旧的 org.codehaus.mojo:hibernate3-maven-plugin。
  • 配置中需明确数据库连接信息(jdbcConnection 节点),因为反向生成实体需要直接连接数据库。
  • 选用 Hibernate 5.6.x 版本,该版本完全兼容 JDK 11。
  • 移除了不必要的依赖(如 hibernate-entitymanager,Hibernate 5+ 已整合至 hibernate-core)。

执行命令

替换插件后,执行以下命令生成实体类:

mvn hibernate-tools:hbm2java

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 11:08:25