当前位置: 首页 > 知识库问答 >
问题:

更正应用程序的类路径,使其包含org.hibernate.internal.SessionFactoryImpl的单一兼容版本

赏航
2023-03-14

我正在尝试通过hibernate和Spring-Boot连接MongoDB数据库。当我试图连接到MongoDB时,我得到了以下错误。请帮我通过Hibernate连接。在我的build.gradle中,我只有“hibernate-ogm-mongoDB”依赖项。

compile group: 'org.hibernate.ogm', name: 'hibernate-ogm-mongodb', version: '5.4.1.Final'
<?xml version="1.0"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
    version="2.0">
    <persistence-unit name="MyMongoDB"
        transaction-type="JTA">
        <provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
        <properties>
            <property name="hibernate.ogm.datastore.provider"
                value="MONGODB" />
            <property name="hibernate.ogm.datastore.database"
                value="testdb" />
            <property name="hibernate.ogm.datastore.host"
                value="localhost" />
            <property name="hibernate.ogm.datastore.port"
                value="27017" />
            <property name="hibernate.ogm.datastore.create_database"
                value="true" />
        </properties>
    </persistence-unit>
</persistence>
@Bean
public EntityManagerFactory createEntityManagerFactory() {
    EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("MyMongoDB");
    return entityManagerFactory;
}
org.hibernate.ogm.boot.impl.OgmSessionFactoryBuilderImpl.build(OgmSessionFactoryBuilderImpl.java:56)
void org.hibernate.internal.SessionFactoryImpl.<init>(org.hibernate.boot.spi.BootstrapContext, org.hibernate.boot.spi.MetadataImplementor, org.hibernate.boot.spi.SessionFactoryOptions)
jar:file:/C:/Users/Myuser/.gradle/caches/modules-2/files-2.1/org.hibernate/hibernate-core/5.4.12.Final/7813daed21576920450443097d69823245d112d2/hibernate-core-5.4.12.Final.jar!/org/hibernate/internal/SessionFactoryImpl.class
file:/C:/Users/Myuser/.gradle/caches/modules-2/files-2.1/org.hibernate/hibernate-core/5.4.12.Final/7813daed21576920450443097d69823245d112d2/hibernate-core-5.4.12.Final.jar
Correct the classpath of your application so that it contains a single, compatible version of org.hibernate.internal.SessionFactoryImpl

共有1个答案

束飞捷
2023-03-14

Hibernate OGM 5.4.1.final需要Hibernate ORM 5.3.6.final。

项目中的某些依赖项没有对齐。

 类似资料: