更正应用程序的类路径,使其包含 org.hibernate.internal.SessionFactoryImpl 的单一兼容版本
Correct the classpath of your application so that it contains a single, compatible version of org.hibernate.internal.SessionFactoryImpl
我正在尝试通过 spring-boot 通过休眠连接 MongoDB 数据库。在尝试连接到 MongoDB 时,出现以下错误。请帮我通过休眠连接。在我的 build.gradle 中,我只有 "hibernate-ogm-mongodb" 依赖。
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>
配置文件:
@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)
方法的 class、org.hibernate.internal.SessionFactoryImpl 可从以下位置获得:
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
Hibernate OGM 5.4.1.Final 需要 Hibernate ORM 5.3.6.Final.
项目中的一些依赖没有对齐。
我正在尝试通过 spring-boot 通过休眠连接 MongoDB 数据库。在尝试连接到 MongoDB 时,出现以下错误。请帮我通过休眠连接。在我的 build.gradle 中,我只有 "hibernate-ogm-mongodb" 依赖。
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>
配置文件:
@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)
方法的 class、org.hibernate.internal.SessionFactoryImpl 可从以下位置获得:
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
Hibernate OGM 5.4.1.Final 需要 Hibernate ORM 5.3.6.Final.
项目中的一些依赖没有对齐。