Correct the classpath of your application so that it contains a single, compatible version of org.hibernate.internal.SessionFactoryImpl

£可爱£侵袭症+ 提交于 2020-04-30 06:29:12

问题


I'm trying to connect MongoDB database via hibernate with spring-boot. While trying to connect to MongoDB, I'm getting below error. Please help me to connect via hibernate. In my build.gradle, I have "hibernate-ogm-mongodb" dependency only.

Gradle :

compile group: 'org.hibernate.ogm', name: 'hibernate-ogm-mongodb', version: '5.4.1.Final'

persistence.xml:

<?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>

Configuration file :

@Bean
public EntityManagerFactory createEntityManagerFactory() {
    EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("MyMongoDB");
    return entityManagerFactory;
}

Description: An attempt was made to call a method that does not exist. The attempt was made from the following location:

org.hibernate.ogm.boot.impl.OgmSessionFactoryBuilderImpl.build(OgmSessionFactoryBuilderImpl.java:56)

The following method did not exist:

void org.hibernate.internal.SessionFactoryImpl.<init>(org.hibernate.boot.spi.BootstrapContext, org.hibernate.boot.spi.MetadataImplementor, org.hibernate.boot.spi.SessionFactoryOptions)

The method's class, org.hibernate.internal.SessionFactoryImpl, is available from the following locations:

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

It was loaded from the following location:

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

Action:

Correct the classpath of your application so that it contains a single, compatible version of org.hibernate.internal.SessionFactoryImpl

回答1:


Hibernate OGM 5.4.1.Final requires Hibernate ORM 5.3.6.Final.

Some of the dependencies in the project are not aligned.



来源:https://stackoverflow.com/questions/61454923/correct-the-classpath-of-your-application-so-that-it-contains-a-single-compatib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!