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

Eclipse Oxygen中Hibernate无法加载AnnotationConfiguration求助

Let's break down your issues step by step—you're dealing with a mix of version conflicts, misconfigured XML, and tooling compatibility problems. Here's how to fix each one:

1. Fix the AnnotationConfiguration Error & Dependency Conflicts

Hibernate 5.x removed AnnotationConfiguration—it's now merged into the core Configuration class. Your problem stems from two key issues:

  • The old hibernate-annotations dependency (3.5.6-Final) is completely incompatible with Hibernate Core 5.3.0.CR2. Hibernate 3.6+ already includes annotation support directly in hibernate-core, so this dependency is redundant and causes version conflicts.
  • Eclipse Oxygen's Hibernate Tools plugin might be targeting older Hibernate versions, which still looked for the deprecated AnnotationConfiguration class.

Updated pom.xml (remove the conflicting dependency):

<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>
  <groupId>org.cabrera.ebookr</groupId>
  <artifactId>ebookr</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <dependencies>
    <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>4.0.1</version>
      <scope>provided</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.struts/struts-core -->
    <dependency>
      <groupId>org.apache.struts</groupId>
      <artifactId>struts-core</artifactId>
      <version>1.3.10</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.struts/struts-taglib -->
    <dependency>
      <groupId>org.apache.struts</groupId>
      <artifactId>struts-taglib</artifactId>
      <version>1.3.10</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>8.0.11</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-core</artifactId>
      <version>5.3.0.CR2</version>
    </dependency>
  </dependencies>
</project>

2. Fix hibernate.cfg.xml Misconfiguration

Your current XML has two critical mistakes:

  • Wrong DOCTYPE: You mixed up the Hibernate Configuration DTD with the Reverse Engineering DTD. The hibernate.cfg.xml needs the dedicated configuration DTD, not the reverse-engineering one.
  • Outdated MySQL settings: For MySQL Connector/J 8.0+, the driver class, dialect, and URL format have changed (timezone parameter is now required).

Updated hibernate.cfg.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <!-- Updated MySQL 8.0+ driver class -->
        <property name="hibernate.connection.driver_class">com.mysql.cj.jdbc.Driver</property>
        <property name="hibernate.connection.password">test</property>
        <!-- Added mandatory timezone parameter for MySQL 8.0 -->
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/ebookr?serverTimezone=UTC</property>
        <property name="hibernate.connection.username">webuser</property>
        <!-- Updated dialect for MySQL 8.0 -->
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL8Dialect</property>
    </session-factory>
</hibernate-configuration>

3. Fix Reverse Engineering & Eclipse Tooling Issues

Eclipse Oxygen's Hibernate Tools have known compatibility gaps with Hibernate 5.2+. If you still can't generate model classes via Eclipse, use Maven's Hibernate Tools plugin instead—it's more reliable for newer Hibernate versions.

Add this plugin to your pom.xml (inside the <build><plugins> section):

<build>
    <plugins>
        <plugin>
            <groupId>org.hibernate.tool</groupId>
            <artifactId>hibernate-tools-maven-plugin</artifactId>
            <version>5.3.0.CR2</version>
            <dependencies>
                <dependency>
                    <groupId>org.hibernate</groupId>
                    <artifactId>hibernate-core</artifactId>
                    <version>5.3.0.CR2</version>
                </dependency>
                <dependency>
                    <groupId>mysql</groupId>
                    <artifactId>mysql-connector-java</artifactId>
                    <version>8.0.11</version>
                </dependency>
            </dependencies>
            <configuration>
                <jdbcDriver>com.mysql.cj.jdbc.Driver</jdbcDriver>
                <jdbcUrl>jdbc:mysql://localhost:3306/ebookr?serverTimezone=UTC</jdbcUrl>
                <jdbcUser>webuser</jdbcUser>
                <jdbcPassword>test</jdbcPassword>
                <packageName>org.cabrera.ebookr.model</packageName>
                <outputDirectory>src/main/java</outputDirectory>
                <!-- Uncomment below if you want to generate DAOs alongside model classes -->
                <!-- <generateDao>true</generateDao> -->
            </configuration>
        </plugin>
    </plugins>
</build>

Run this Maven command to generate your model classes directly:

mvn hibernate-tools:hbm2java

4. Fix the "Unhandled event loop exception" Error

This Eclipse error is usually a side effect of the earlier configuration issues (wrong DTD, missing dependencies, outdated driver settings). Once you fix the hibernate.cfg.xml and pom.xml, restart Eclipse and try creating the configuration file again—it should resolve automatically.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 09:28:15