Reputation: 97
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. The code ran on another machine so it should work, but I'm assuming I might have a error with MongoDB. The error starts when trying to build a 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. I tried changing the database name to testDB but that didn't seem to make a difference. 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.
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.
Upvotes: 1
Views: 344
Reputation: 1311
Try to add
<property name="hibernate.ogm.datastore.create_database" value="true" />
to the properties section in your persistence.xml
Upvotes: 1