[英]Hibernate OGM: Having trouble starting MongoDB database
So I'm pretty new to MongoDB as well as Hibernate and I'm trying to run a test to connect and add documents to a MongoDB database.所以我对 MongoDB 和 Hibernate 还是很陌生,我正在尝试运行一个测试来连接和添加文档到 MongoDB 数据库。 The code ran on another machine so it should work, but I'm assuming I might have a error with MongoDB.代码在另一台机器上运行,所以它应该可以工作,但我假设我的 MongoDB 可能有错误。 The error starts when trying to build a EntitiyManagerFactory.尝试构建 EntitiyManagerFactory 时开始出现错误。 I get:我得到:
Unable to Build entity manger factory
Caused by: Unable to start datastore provider
Caused by: OGM001219: Database testDB does not exist. Either create it yourself or set property 'hibernate.ogm.datastore.create_database' to true.
I do have mongo running first, and it starts up listening on localhost:27017.我确实先运行了 mongo,然后它开始侦听 localhost:27017。 I tried changing the database name to testDB but that didn't seem to make a difference.我尝试将数据库名称更改为 testDB 但这似乎没有什么区别。 I am able to connect through the command line.我可以通过命令行连接。 Heres a screenshot at startup.这是启动时的屏幕截图。
As a note, I'm not sure if the 3 other connections are normal.请注意,我不确定其他 3 个连接是否正常。
My persistence file looks like.我的持久性文件看起来像。
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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">
<persistence-unit name="jpa-mongodb" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<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.username" value="" />
<property name="hibernate.ogm.datastore.password" value="" />
</properties>
Sorry for the long post but I'm relativity new to this and most resources about Hibernate seemed to assume you could connect.很抱歉这篇长篇文章,但我对这个比较陌生,大多数关于 Hibernate 的资源似乎都假设你可以连接。
Try to add尝试添加
<property name="hibernate.ogm.datastore.create_database" value="true" />
to the properties section in your persistence.xml到persistence.xml中的属性部分
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.