gpt4 book ai didi

java - NoSQL 数据存储提供程序 : org. hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider

转载 作者:可可西里 更新时间:2023-11-01 09:44:18 26 4
gpt4 key购买 nike

我正在尝试使用此 persistence.xml 文件连接到 MongoDB。我的 mongodb 实例没有使用任何用户名或密码。

    <?xml version="1.0" encoding="UTF-8"?>
<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="tryAll" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
<class>com.learning.beans.User</class>
<properties>
<!-- <property name="hibernate.ogm.datastore.provider" value="MONGODB"/> -->
<property name="hibernate.ogm.datastore.provider" value="org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider"/>
<property name="hibernate.ogm.mongodb.database" value="test"/>
<property name="hibernate.ogm.mongodb.host" value="127.0.0.1"/>
<property name="hibernate.ogm.mongodb.port" value="27017"/>
</properties>
</persistence-unit>
</persistence>

我正在使用这个创建一个 EntityManager 实例:

    EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("tryAll");
EntityManager manager = entityManagerFactory.createEntityManager();

我看不出这段代码有什么问题...??

完整的错误栈如下:

    Aug 01, 2014 1:39:34 PM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
Aug 01, 2014 1:39:34 PM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
Aug 01, 2014 1:39:34 PM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
Aug 01, 2014 1:39:34 PM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing PersistenceUnitInfo [
name: tryAll
...]
Aug 01, 2014 1:39:34 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.5.Final}
Aug 01, 2014 1:39:34 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Aug 01, 2014 1:39:34 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Aug 01, 2014 1:39:34 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
Aug 01, 2014 1:39:34 PM org.hibernate.ogm.datastore.impl.DatastoreProviderInitiator initiateService
INFO: OGM000016: NoSQL Datastore provider: org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider
Exception in thread "main" javax.persistence.PersistenceException: Unable to build entity manager factory
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:83)
at org.hibernate.ogm.jpa.HibernateOgmPersistence.createEntityManagerFactory(HibernateOgmPersistence.java:61)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at com.learning.executors.TryExecutor.main(TryExecutor.java:16)
Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.ogm.dialect.GridDialect]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:261)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:225)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.ogm.dialect.impl.OgmDialectFactoryInitiator$OgmDialectFactory.<init>(OgmDialectFactoryInitiator.java:51)
at org.hibernate.ogm.dialect.impl.OgmDialectFactoryInitiator.buildServiceInstance(OgmDialectFactoryInitiator.java:33)
at org.hibernate.ogm.dialect.impl.OgmDialectFactoryInitiator.buildServiceInstance(OgmDialectFactoryInitiator.java:27)
at org.hibernate.ogm.service.impl.OptionalServiceInitiator.initiateService(OptionalServiceInitiator.java:23)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:105)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:251)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:225)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:95)
at org.hibernate.ogm.service.impl.OgmJdbcServicesInitiator$OgmJdbcServicesImpl.configure(OgmJdbcServicesInitiator.java:56)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:397)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842)
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:75)
... 4 more
Caused by: org.hibernate.HibernateException: OGM000052: Missing value for property 'hibernate.ogm.datastore.database'
at org.hibernate.ogm.util.configurationreader.impl.PropertyReaderContext.getValue(PropertyReaderContext.java:101)
at org.hibernate.ogm.cfg.impl.DocumentStoreConfiguration.<init>(DocumentStoreConfiguration.java:44)
at org.hibernate.ogm.datastore.mongodb.impl.configuration.MongoDBConfiguration.<init>(MongoDBConfiguration.java:60)
at org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider.configure(MongoDBDatastoreProvider.java:68)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.ogm.dialect.impl.GridDialectInitiator.initiateService(GridDialectInitiator.java:47)
at org.hibernate.ogm.dialect.impl.GridDialectInitiator.initiateService(GridDialectInitiator.java:34)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:105)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:251)
... 26 more

最佳答案

您缺少的是 three more propertiespersistence.xml 中配置数据库连接:

  • hibernate.ogm.mongodb.database
    The database to connect to. This property has no default value.
  • hibernate.ogm.mongodb.username
    The username used when connecting to the MongoDB server. This property has no default value.
  • hibernate.ogm.mongodb.password
    The password used to connect to the MongoDB server. This property has no default value. This property is ignored if the username isn’t specified.

你会发现here您还可以使用更通用的属性。

Properties common to all/most stores are named hibernate.ogm.datastore.* now, so e.g. there is hibernate.ogm.datastore.host, hibernate.ogm.datastore.username, hibernate.ogm.datastore.database etc. Properties specific to a single store are named hibernate.ogm..*, e.g. hibernate.ogm.mongodb.connection_timeout.

关于java - NoSQL 数据存储提供程序 : org. hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25076975/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com