I have an application that is written in Java and was written before by someone else before I got control of it. We are using MongoDB with a replica set. I know that in order to use the replica set properly, you need to pass the driver a "seed list" of all servers associated with the replica set in order for it to choose the primary.

The problem is that the application is using Hibernate to connect to MongoDB. Is there a way to specify the seed list inside the Hibernate xml configuration file? Below is a sample of what we have configured in the application.

<hibernate-configuration>
    <session-factory>
        <property name="hibernate.ogm.datastore.provider">MONGODB</property>
        <property name="dialect">org.hibernate.ogm.dialect.mongodb.MongoDBDialect</property>
        <property name="hibernate.ogm.mongodb.database">databasename</property>
        <property name="hibernate.ogm.mongodb.host">192.168.1.10</property>
        <property name="hibernate.ogm.mongodb.port">27017</property>
        <mapping resource="mongodb.hbm.xml" />
    </session-factory>
</hibernate-configuration>

I tried to find documentation on the list of properties for this configuration and didn't see anything about specifying multiple hosts for a seed list; hibernate.ogm.mongodb.host is the only thing I could find and as far as I know, it only supports 1 host.

Any ideas on how I can make the current application work with a replica set seed list using hibernate?

有帮助吗?

解决方案

The latest versions of Hibernate OGM support this via the property:

hibernate.ogm.datastore.host

Here's an example of a valid value:

www.example.com, www2.example.com:123, 192.0.2.1, 192.0.2.2:123, 2001:db8::ff00:42:8329, [2001:db8::ff00:42:8329]:123

The default value is 127.0.0.1:27017. If left undefined, the default port is 27017.

There are more details in the official documentation

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top