2016-10-02 2 views
1

저는 MongoDB와 Hibernate를 처음 접했고 MongoDB 데이터베이스에 연결하고 문서를 추가하는 테스트를 실행하려고합니다. 코드가 다른 컴퓨터에서 실행 되었기 때문에 작동해야하지만 MongoDB에 오류가 있다고 가정합니다. EntitiyManagerFactory를 빌드 할 때 오류가 시작됩니다. 나는 다음을 얻는다 :Hibernate OGM : MongoDB 데이터베이스를 시작하는 데 문제가 있습니다.

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. 

나는 몽고가 먼저 달리고, localhost : 27017에서 듣기 시작한다. 나는 데이터베이스 이름을 testDB로 변경하려고 시도했지만 그 차이는 없다. 명령 줄을 통해 연결할 수 있습니다. 시작할 때의 스크린 샷을 보여줍니다.

enter image description here

는 참고로, 나는 3 개 다른 연결은 정상 있는지 확실하지 않습니다.

내 영속성 파일은 다음과 같습니다.

<?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> 

긴 게시물에 대한 죄송

그러나 나는이에 상대성 새로운 해요 및 최대 절전 모드에 대한 대부분의 자원을 연결할 수있는 가정하는 것 같았다.

답변

1

시도 당신의 persistence.xml의 속성 섹션에

<property name="hibernate.ogm.datastore.create_database" value="true" /> 

를 추가 할 수

관련 문제