![](/img/trans.png)
[英]Fail to connect to MongoDB via HibernateOGM using sessionFactory
[英]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.