1
我想用HibernateOGM與MongoDB的交互連接到MongoDB的。我有一個cfg.xml
文件是這樣的:無法使用HibernateOGM
<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... :)");
我有這個代碼不輸出,並且也沒有例外
info行:
這是我的項目的結構:
肯定的,但UO說,我在配置文件中定義它,你知道,我怎麼能解決我的問題? – TangoStar
我想,你的配置文件沒有被檢測到。 – user2550754
是的,我認爲是這樣的: – TangoStar