作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用 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)
信息行:
这是我的项目的结构:
最佳答案
您已在配置文件中指定MongoDBDialect
。但在控制台日志中,您将在 HHH000400
上获取 NoopDialect
。在下一行中,您将得到connection was null
。最后一行是,无法创建请求的服务
。
关于java - 无法使用 HibernateOGM 连接到 Mongodb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18101922/
我想使用 HibernateOGM 与 MongoDB 交互。我有一个像这样的 cfg.xml 文件: org.transaction.JDBCTransactionFactory
我正在使用 hibernate OGM 与我的 MongoDB 实例对话。我必须获取类别为“abc”的所有产品的列表。我使用 native 查询方法来实现此目的,如下所示: String string
今天,我想使用 Spring Boot 自动创建 MongoDB 的数据库结构。过去在关系数据库中,我在 application.properties 文件中使用两个属性,例如: spring.jpa
我是一名优秀的程序员,十分优秀!