我可以使用以下方法在我的mongo实例上成功访问:
#mongo -u user -p pwd -authenticationDatabase admin database
然而,使用Hibernate OGM我无法访问mongo实例:
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="mongo" transaction-type="JTA">
<provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
<properties>
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />
<property name="hibernate.ogm.datastore.provider" value="org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider"/>
<property name="hibernate.ogm.datastore.database" value="database"/>
<property name="hibernate.ogm.datastore.host" value="mongo"/>
<property name="hibernate.ogm.datastore.port" value="27017"/>
<property name="hibernate.ogm.datastore.username" value="user"/>
<property name="hibernate.ogm.datastore.password" value="pwd"/>
<property name="hibernate.ogm.mongodb.connection_timeout" value="5000"></property>
<property name="hibernate.ogm.mongodb.authentication_mechanism" value="PLAIN"></property>
<property name="hibernate.ogm.datastore.document.association_storage" value="IN_ENTITY"></property>
<property name="hibernate.ogm.mongodb.association_document_storage" value="GLOBAL_COLLECTION"></property>
<property name="hibernate.ogm.mongodb.write_concern" value="MAJORITY"></property>
<property name="hibernate.ogm.mongodb.read_preference" value="PRIMARY_PREFERRED"></property>
</properties>
</persistence-unit>
</persistence>
我得到的信息是我试图启动应用程序的时候:
Caused by: org.hibernate.HibernateException: OGM001214: Unable to connect to MongoDB instance mongo:27017,
at org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider.extractDatabase(MongoDBDatastoreProvider.java:192)
at org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider.start(MongoDBDatastoreProvider.java:117)
... 39 more
Caused by: com.mongodb.CommandFailureException: { "serverUsed" : "mongo:27017" , "ok" : 0.0 , "errmsg" : "no such cmd: saslStart" , "code" : 59 , "bad cmd" : { "saslStart" : 1 , "mechanism" : "PLAIN" , "payload" : <Binary Data>}}
at com.mongodb.CommandResult.getException(CommandResult.java:76)
at com.mongodb.CommandResult.throwOnError(CommandResult.java:140)
at com.mongodb.DBPort$SaslAuthenticator.authenticate(DBPort.java:899)
at com.mongodb.DBPort.authenticate(DBPort.java:432)
at com.mongodb.DBPort.checkAuth(DBPort.java:443)
at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:293)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:273)
at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:84)
at com.mongodb.DBCollectionImpl.find(DBCollectionImpl.java:66)
at com.mongodb.DBApiLayer.getCollectionNames(DBApiLayer.java:169)
at com.mongodb.DB.collectionExists(DB.java:524)
at org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider.extractDatabase(MongoDBDatastoreProvider.java:183)
... 40 more
我正在使用:
compile group: 'org.hibernate.ogm', name: 'hibernate-ogm-mongodb', version: '4.2.0.Final'
mongo版本是2.6。
答案 0 :(得分:0)
这似乎是版本问题。 Hibernate OGM 4.2.0.Final应该与MongoDB 2.13.1一起使用