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

求助:导入SessionFactory时遇org.hibernate包多模块冲突问题

Fixing the "org.hibernate accessible from more than one module" Error

Hey there! Let's work through this package conflict issue you're hitting with Hibernate. That error pops up because the Java module system (introduced in Java 9) detects that the org.hibernate package is being exported by two different modules—hibernate.commons.annotations and hibernate.core—which breaks module rules. Here's how to fix it:

  • Remove redundant Hibernate dependencies
    Starting with Hibernate 5.3+, the hibernate-commons-annotations library is already bundled into hibernate-core. If you added both dependencies separately (like in your pom.xml or build.gradle), delete the standalone hibernate-commons-annotations entry entirely. This is the most common root cause of this conflict.

  • Exclude conflicting transitive dependencies (if needed)
    Sometimes other dependencies might pull in hibernate-commons-annotations as a transitive dependency. For Maven, explicitly exclude it from your hibernate-core dependency:

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>your-hibernate-version</version>
        <exclusions>
            <exclusion>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-commons-annotations</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    

    For Gradle, use this syntax:

    implementation('org.hibernate:hibernate-core:your-hibernate-version') {
        exclude group: 'org.hibernate', module: 'hibernate-commons-annotations'
    }
    
  • Clean up your module-info.java (if using Java modules)
    If your project uses the Java Module System (you have a module-info.java file), make sure you only require the org.hibernate.core module. Remove any line like requires org.hibernate.commons.annotations;—those packages are already covered by requires org.hibernate.core;.

  • Clear IDE caches
    IDEs can sometimes hold onto outdated module metadata. Try invalidating caches and restarting:

    • In IntelliJ IDEA: Go to File > Invalidate Caches... and select "Invalidate and Restart"
    • In Eclipse: Go to Project > Clean... and rebuild your project

Also, double-check that all your Hibernate dependencies use the same version—mixing different versions can trigger weird module conflicts too.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 11:01:36