I'm struggling to connect my jboss running on my local machine to a MongoDB database in Openshift.
It works fine using a local database (localhost:27017).
My persistence.xml:
<?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_1_0.xsd"
version="1.0">
<persistence-unit name="mongodb-PU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
<class>com.commons.db.model.User</class
<properties>
<property name="hibernate.ogm.datastore.provider" value="mongodb" />
<property name="hibernate.ogm.datastore.database" value="test" />
<property name="hibernate.ogm.datastore.create_database" value="true" />
<property name="hibernate.transaction.jta.platform"
value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform"/>
<!-- Running on local machine with local dataabse details -->
<!--
<property name="hibernate.ogm.mongodb.host" value="localhost" />
<property name="hibernate.ogm.mongodb.port" value="27017" />
-->
<!-- Running on openshift locally with port forwarding -->
<!-- -->
<property name="hibernate.ogm.mongodb.host" value="127.0.0.1" />
<property name="hibernate.ogm.mongodb.port" value="44506" />
<property name="hibernate.ogm.mongodb.username" value="admin" />
<property name="hibernate.ogm.mongodb.password" value="password" />
<!-- -->
</properties>
</persistence-unit>
</persistence>
I ran the rch port forwarding command.
rhc port-forward -a test-app
And it returned the correct port forwarding:
haproxy 127.0.0.1:8081 => 127.4.173.2:8080
haproxy 127.0.0.1:8082 => 127.4.173.3:8080
java 127.0.0.1:3528 => 127.4.173.1:3528
java 127.0.0.1:4448 => 127.4.173.1:4447
java 127.0.0.1:5445 => 127.4.173.1:5445
java 127.0.0.1:5455 => 127.4.173.1:5455
java 127.0.0.1:8083 => 127.4.173.1:8080
java 127.0.0.1:9991 => 127.4.173.1:9990
java 127.0.0.1:10000 => 127.4.173.1:9999
mongodb 127.0.0.1:44506 => 54c685bf5973cac227000040-*****.rhcloud.com:44506
mysql 127.0.0.1:54231 => 54c687b95973ca28650000a9-*****.rhcloud.com:54231
And I'm able to connect to the mongo database using
mongo --host 127.0.0.1 --port 44506
But when I try to boot up my jboss server with the persistence.xml I showed you above. It always tries to connect to the localhost:27017. Returning this error:
Caused by: org.hibernate.HibernateException: OGM001214: Unable to connect to MongoDB instance localhost:27017
at org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider.extractDatabase(MongoDBDatastoreProvider.java:167)
at org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider.start(MongoDBDatastoreProvider.java:110)
... 37 more
Caused by: com.mongodb.MongoTimeoutException: Timed out after 5000 ms while waiting to connect. Client view of cluster state is {type=Unknown, servers
=[{address=localhost:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {j
ava.net.ConnectException: Connection refused}}]
at com.mongodb.BaseCluster.getDescription(BaseCluster.java:128)
at com.mongodb.DBTCPConnector.getClusterDescription(DBTCPConnector.java:396)
at com.mongodb.DBTCPConnector.getType(DBTCPConnector.java:569)
at com.mongodb.DBTCPConnector.getReplicaSetStatus(DBTCPConnector.java:364)
at com.mongodb.Mongo.getReplicaSetStatus(Mongo.java:465)
at com.mongodb.DB.getCommandReadPreference(DB.java:86)
at com.mongodb.DB.command(DB.java:314)
at com.mongodb.DB.command(DB.java:296)
at com.mongodb.DB.command(DB.java:371)
at com.mongodb.Mongo.getDatabaseNames(Mongo.java:396)
at org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider.extractDatabase(MongoDBDatastoreProvider.java:152)
... 38 more
Does any of you had similar issues while trying to connect from local server to an Openshift hosted database using the persistence.xml?
Thank you
which version of OGM are you using?
In the latest version the properties to specify host and port are:
hibernate.ogm.datastore.host
hibernate.ogm.datastore.port