unable to connect to Mongodb using HibernateOGM

1k Views Asked by At

I want to use HibernateOGM to interact with MongoDB. I have an cfg.xml file like this:

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

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: enter image description here

This is the structure of my project: enter image description here

2

There are 2 best solutions below

16
On

You have specified MongoDBDialect in the configuration file. But on the console log, you are getting NoopDialect on HHH000400. And in the next line, you are getting connection was null. And the last line is, Unable to create requested service.

0
On

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

I puzzled over this for two days