简体   繁体   English

无法使用 HibernateOGM 连接到 Mongodb

[英]unable to connect to Mongodb using HibernateOGM

I want to use HibernateOGM to interact with MongoDB.我想使用 HibernateOGM 与 MongoDB 进行交互。 I have an cfg.xml file like this:我有一个像这样的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>

I have also wrote my POJO class, and in the main class I want to populate the database in the mongodb with this code, but I am not able to do this job and I get these line of Infos, how can I solve that:我也写了我的 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... :)");

I have no output with this code, and also no exceptions我没有这个代码的输出,也没有例外

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

This is the structure of my project:这是我的项目结构:在此处输入图片说明

You have specified MongoDBDialect in the configuration file.您已在配置文件中指定了MongoDBDialect But on the console log, you are getting NoopDialect on HHH000400 .但是在控制台日志上,您会在NoopDialect上获得HHH000400 And in the next line, you are getting connection was null .在下一行中,您将得到connection was null And the last line is, Unable to create requested service .最后一行是, Unable to create requested service

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

I puzzled over this for two days纠结了两天

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

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