I am developing an application that uses Hibernate OGM to work with MongoDB. sessionFactory is used to connect, encountered an error while configuring. Log:
...
2020-12-21 11:09:06 INFO DatastoreProviderInitiator:51 - OGM000016: NoSQL Datastore provider: org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider
2020-12-21 11:09:06 ERROR HibernateDataProvider:108 - org.hibernate.service.spi.ServiceException: OGM000072: Unable to configure datastore provider
Class HibernateUtil to get sessionFactory:
import org.hibernate.cfg.Configuration;
import org.hibernate.SessionFactory;
import org.hibernate.ogm.cfg.OgmConfiguration;
public class HibernateUtil {
private static SessionFactory sessionFactory;
public static SessionFactory getSessionFactory() {
if (sessionFactory == null) {
Configuration configuration = new OgmConfiguration();
//assuming the default mongodb settings
configuration.setProperty("hibernate.ogm.datastore.provider",
"MONGODB");
configuration.setProperty("hibernate.ogm.mongodb.host",
"127.0.0.1");
configuration.setProperty("hibernate.ogm.mongodb.port",
"27017");
configuration.setProperty("hibernate.ogm.mongodb.database",
"test");
configuration.setProperty("hibernate.ogm.datastore.create__database",
"true");
sessionFactory = configuration.buildSessionFactory();
}
return sessionFactory;
}
}
How to fix this problem?
You are missing the
hibernate-ogm-mongodb
dependency: https://mvnrepository.com/artifact/org.hibernate.ogm/hibernate-ogm-mongodb