gpt4 book ai didi

java - 无法使用 HibernateOGM 连接到 Mongodb

转载 作者:行者123 更新时间:2023-12-01 04:29:40 25 4
gpt4 key购买 nike

我想使用 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... :)");

这段代码没有输出,也没有异常(exception)

信息行: enter image description here

这是我的项目的结构: enter image description here

最佳答案

您已在配置文件中指定MongoDBDialect。但在控制台日志中,您将在 HHH000400 上获取 NoopDialect。在下一行中,您将得到connection was null。最后一行是,无法创建请求的服务

关于java - 无法使用 HibernateOGM 连接到 Mongodb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18101922/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com