0

我有个问题。我是hibernate的新手,我想用HibernateOGM写一个非常简单的例子。我得到一个例外,上面写着:

引起:org.hibernate.HibernateException:无法实例化指定的TransactionFactory类[org.transaction.JDBCTransactionFactory]

我已经搜索了很多,但我找不到任何解决我的问题的方法。据我了解,问题出现在这一行:

sessionfactory=cfgogm.buildSessionFactory(serviceregistry);

如果我评论其他行,我也不例外,只有 INFOS。

这是我的堆栈跟踪:

at org.hibernate.engine.transaction.internal.TransactionFactoryInitiator.initiateService(TransactionFactoryInitiator.java:80)
    at org.hibernate.ogm.transaction.impl.OgmTransactionFactoryInitiator.buildServiceInstance(OgmTransactionFactoryInitiator.java:61)
    at org.hibernate.ogm.transaction.impl.OgmTransactionFactoryInitiator.buildServiceInstance(OgmTransactionFactoryInitiator.java:41)
    at org.hibernate.ogm.service.impl.OptionalServiceInitiator.initiateService(OptionalServiceInitiator.java:37)
    at org.hibernate.service.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:69)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:176)

在这里你可以找到我的代码和 hibernate.cfg.xml 和 pom.xml:

 OgmConfiguration cfgogm=new OgmConfiguration();
            cfgogm.configure("hibernate.cfg.xml");
            serviceregistry=new ServiceRegistryBuilder().applySettings(cfgogm.getProperties()).buildServiceRegistry();
            sessionfactory=cfgogm.buildSessionFactory(serviceregistry)

hibernate.cfg.xml是:

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>  
  <session-factory>


    <property name="hibernate.current_session_context_class">thread</property>
    <property name="hibernate.ogm.datastore.grid_dialect">org.hibernate.ogm.dialect.mongodb.MongoDBDialect</property>
    <property name="hibernate.ogm.datastore.provider">mongodb</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>
    <mapping resource="hibernate-contact.hbm.xml"/>
  </session-factory>
</hibernate-configuration>

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>hogm</groupId>
  <artifactId>HibernateOGM_MongoDB</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>HibernateOGM_MongoDB</name>
  <url>http://maven.apache.org</url>
  <build>
          <plugins>
              <plugin>
                  <groupId>org.codehaus.mojo</groupId>
                  <artifactId>exec-maven-plugin</artifactId>
                  <version>1.2.1</version>
                  <executions>
                      <execution>
                          <goals>
                                  <goal>exec</goal>
                          </goals>
                      </execution>
                  </executions>
              </plugin>
          </plugins>
  </build>

 <dependencies>
     <dependency>
         <groupId>org.hibernate.ogm</groupId>
         <artifactId>hibernate-ogm-mongodb</artifactId>
         <version>4.0.0.Beta1</version>
     </dependency>
     <dependency>
         <groupId>org.hibernate.ogm</groupId>
         <artifactId>hibernate-ogm-core</artifactId>
         <version>4.0.0.Beta2</version>
     </dependency>   

  <dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>4.11</version>
   <scope>test</scope>
   <type>jar</type>
  </dependency>
 </dependencies>
</project>

你能帮我解决这个问题吗?

4

2 回答 2

2

正确的类名是 org。休眠.transaction.JDBCTransactionFactory。

hibernate 可能会使用不正确的类名获取一些属性或属性文件。

如果找不到,请在自己的 hibernate.cfg.xml 中覆盖它:

<property  name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
于 2013-08-14T14:04:34.217 回答
1

Hibernate Object/Grid Mapper (OGM) 是一个持久化引擎,为NoSQL数据存储提供 Java Persistence (JPA) 支持。那么为什么要在 derby中使用hibernate-ogm呢?

查看使用 mangoDB 的 hibernate-ogm 官方指南

- 编辑 -

您的任何配置文件中是否有类似JDBCTransactionFactory的内容?尝试删除它。

于 2013-08-14T12:59:17.460 回答