使用hibernate为PostgreSQL运行java项目,使用hibernate ogm运行MongoDB

时间:2016-10-30 10:25:22

标签: mongodb postgresql hibernate hibernate-ogm

我使用jpa从Play访问PG。我还需要访问MongoDB。一旦我将mongo依赖项添加到相关的pom.xml,我就会得到运行时异常,例如:

[INFO] --- play2-maven-plugin:1.0.0-beta5:run (default-cli) @ API ---
[INFO] Launching Play! server
 [play] Listening for transport dt_socket at address: 1045
 [play] [warn] o.h.e.j.c.i.DriverManagerConnectionProviderImpl - HHH000402: Using Hibernate built-in connection pool (not for production use!)
 [play] java.lang.AbstractMethodError
 [play]     at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:278)
 [play]     at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
 [play]     at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:802)
 [play]     at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:58)
 [play]     at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
 [play]     at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)

虽然我有这些依赖项,但它有效:

  <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.0.2.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>5.0.2.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-search</artifactId>
        <version>5.0.1.Final</version>
    </dependency>

一旦我添加了这些,就会带来运行时异常:

    <dependency>
        <groupId>org.hibernate.ogm</groupId>
        <artifactId>hibernate-ogm-core</artifactId>
        <version>5.0.2.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate.ogm</groupId>
        <artifactId>hibernate-ogm-mongodb</artifactId>
        <version>5.0.2.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate.ogm</groupId>
        <artifactId>hibernate-ogm-infinispan</artifactId>
        <version>5.0.2.Final</version>
    </dependency>

1 个答案:

答案 0 :(得分:0)

通过向pom.xml添加更多依赖项解决了该问题:

    <dependency>
        <groupId>dom4j</groupId>
        <artifactId>dom4j</artifactId>
        <version>1.6.1</version>
    </dependency>
    <dependency>
        <groupId>xml-apis</groupId>
        <artifactId>xml-apis</artifactId>
        <version>1.4.01</version>
    </dependency>
   <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-search</artifactId>
        <version>5.5.5.Final</version>
    </dependency>