无法使用sessionfactory通过hibernateogm连接到mongodb

hrysbysz  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(195)

我正在开发一个使用hibernate ogm与mongodb一起工作的应用程序。sessionfactory用于连接,配置时遇到错误。日志:

...
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

类hibernateutil以获取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;
    }
}

如何解决这个问题?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题