繁体   English   中英

无法使用 HibernateOGM 连接到 Mongodb

[英]unable to connect to Mongodb using HibernateOGM

我想使用 HibernateOGM 与 MongoDB 进行交互。 我有一个像这样的cfg.xml文件:

<hibernate-configuration>
  <session-factory>
      <property name="hibernate.transaction.factory_class">org.transaction.JDBCTransactionFactory</property>
      <property name="hibernate.current_session_context_class">thread</property>
      <property name="hibernate.ogm.datastore.provider">mongodb</property>
      <property name="hibernate.ogm.datastore.grid_dialect">org.hibernate.ogm.dialect.MongoDBDialect</property>
      <property name="hibernate.ogm.mongodb.database">rcfdb</property>
      <property name="hibernate.ogm.mongodb.host">127.0.0.1</property>
      <property name="hibernate.ogm.mongodb.port">27017</property>
      <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
      <mapping resource="hibernate-contact.hbm.xml"/>    
  </session-factory>
</hibernate-configuration>

我也写了我的 POJO 类,在主类中我想用这段代码填充 mongodb 中的数据库,但我无法完成这项工作,我得到了这些信息行,我该如何解决:

Session session=null;
            OgmConfiguration cfgogm=new OgmConfiguration();
            SessionFactory sessionfactory= cfgogm.buildSessionFactory();
            session=sessionfactory.openSession();
            session.beginTransaction();

            System.out.println("Populating the database...");
            Contact cnt=new Contact();
            cnt.setFirstname("Blabla");
            cnt.setLastname("Blabla");
            cnt.setEmail("blabla");
            session.save(cnt);
            session.getTransaction().commit();
            System.out.println("Done... :)");

我没有这个代码的输出,也没有例外

信息行:在此处输入图片说明

这是我的项目结构:在此处输入图片说明

您已在配置文件中指定了MongoDBDialect 但是在控制台日志上,您会在NoopDialect上获得HHH000400 在下一行中,您将得到connection was null 最后一行是, Unable to create requested service

hibernate.ogm.mongodb.port -> hibernate.ogm.datastore.port

纠结了两天

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM