Obaid Maroof Obaid Maroof - 5 months ago 45
Java Question

Enable SSL for mongoDB using hibernate OGM

I am using hibernate OGM to interact with mongoDB. As part of business requirement, I need to enable

for the communication between mongodb and my java application.

I see in mongodb documentation that using the mongodb-java-driver, it is as simple as turing the ssl flag to true in the connection string. How can I do this in hibernate?

===== UPDATE based on the only given answer ======

Hibernate OGM version 4.2 uses mongodb Java driver version 2.13 which doesn't include the ssl property in MongoClientOptions.Builder class. I can not upgrade hibernateOGM version because its still either beta or alpha. I tried explicitly upgrade the java driver version but then I started getting exception
java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.ogm.datastore.mongodb.options.impl.WriteConcernOption


You can enable SSL using the following property:

hibernate.ogm.mongodb.driver.sslEnabled = true

you can also set:

hibernate.ogm.mongodb.driver.sslInvalidHostNameAllowed = true

HIbernate OGM uses the com.mongodb.MongoClientand you can set all the properties in com.mongod.MongoClientOptions using the prefix hibernate.ogm.mongodb.driver.

Check the documentation and MongoClient.Builder for more details.