Search code examples
javamongodbhibernatehibernate-ogm

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


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

Solution

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

    Some of the dependencies in the project are not aligned.