简体   繁体   English

具有MongoDB持久性异常的Hibernate OGM

[英]Hibernate OGM with MongoDB persistence exception

I fighing with hibernate. 我想休眠。 I'm trying to follow hibernate.org/ogm/documentation/getting-started/ . 我正在尝试遵循hibernate.org/ogm/documentation/getting-started/。 Here are my files - persistence.xml: 这是我的文件-persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="ogm-jpa-tutorial" transaction-type="JTA">
    <!-- Use Hibernate OGM provider: configuration will be transparent -->
    <provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
    <class>com.mycompany.hibernate.MyEntity</class>
    <properties>
      <property name="hibernate.ogm.datastore.provider" value="MONGODB"/>
      <!-- property optional if you plan and use Infinispan, otherwise adjust to your favorite
                NoSQL Datastore provider.
            <property name="hibernate.ogm.datastore.provider"
                      value="org.hibernate.ogm.datastore.infinispan.impl.InfinispanDatastoreProvider"/>
            -->
      <!-- defines which JTA Transaction we plan to use -->
      <property name="hibernate.ogm.datastore.provider" value="org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider"/>
      <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform"/>
    </properties>
  </persistence-unit>
</persistence>

entity class: 实体类:

@Entity
@Table(name = "USstates")
public class MyEntity implements Serializable{
   @Id 
   String _id;
   String city;
   Integer pop;
  String state;
  public String getId(){return _id;}
  public String getCity(){return city;}
  public Integer getPop(){return pop;}
  public String getState(){return state;}

} 

application 应用

private static final String JBOSS_TM_CLASS_NAME = "com.mycompany.hibernate.TransactionManager";
    public static void main( String[] args ) throws Exception
    {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory(
    "ogm-jpa-tutorial");

TransactionManager tm = getTransactionManager();
//Persist entities the way you are used to in plain JPA
tm.begin();

EntityManager em = emf.createEntityManager();
MyEntity e = new MyEntity();
e = new MyEntity();
//Retrieve your entities the way you are used to in plain JPA
tm.begin();
em = emf.createEntityManager();
e = em.find(MyEntity.class, "0");
em.flush();
em.close();
tm.commit();

emf.close();

    }

        public static TransactionManager getTransactionManager() {
try {
Class<?> tmClass = App.class.getClassLoader().loadClass( JBOSS_TM_CLASS_NAME );
return (TransactionManager) tmClass.getMethod( "transactionManager" ).invoke( null );
} catch ( ClassNotFoundException e ) {
e.printStackTrace();
} catch ( InvocationTargetException e ) {
e.printStackTrace();
} catch ( NoSuchMethodException e ) {
e.printStackTrace();
} catch ( IllegalAccessException e ) {
e.printStackTrace();
}
return null;
}

I have database test with collection USstates taken from http://media.mongodb.org/zips.json 我对来自http://media.mongodb.org/zips.json的美国状态集合进行了数据库测试

Using thic codes I got some wornings about logs and what more important exception while running this application: 使用thic代码,我在运行该应用程序时对日志以及更重要的异常有了一些厌倦:

Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: ogm-jpa-tutorial] Unable to build Hibernate SessionFactory

any ideas? 有任何想法吗?

UPDATE: 更新:

after fighting i got an error of non exising class, I already tried milions of combinations of dependency and still got nothing... error: 战斗之后,我遇到了一个不存在类的错误,我已经尝试了数百万种依赖关系的组合,但仍然一无所获...错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/util/xml/Origin 线程“主”中的异常java.lang.NoClassDefFoundError:org / hibernate / util / xml / Origin

UPDATE 2.0: Now I have other problem: UPDATE 2.0:现在我还有其他问题:

Exception in thread "main" java.lang.NoSuchMethodError: org.hibernate.cfg.Configuration.getIdentifierGeneratorFactory()Lorg/hibernate/id/factory/spi/MutableIdentifierGeneratorFactory;
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1119)
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:291)
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:373)
    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:55)
    at org.hibernate.ogm.jpa.HibernateOgmPersistence.createEntityManagerFactory(HibernateOgmPersistence.java:92)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
    at com.mycompany.hibernate.App.main(App.java:48)

Ok silly question - did you remove the specific connection properties from your persistence.xml here, or did you not have them - example below? 好的愚蠢的问题-您是从此处的persistence.xml中删除了特定的连接属性,还是没有它们-下面的示例?

    <property name="hibernate.ogm.datastore.provider" value="mongodb"/>
    <property name="hibernate.ogm.datastore.database" value="rntsmpl"/>
    <property name="hibernate.ogm.datastore.host" value="127.0.0.1"/>
    <property name="hibernate.ogm.datastore.port" value="59541"/>
    <property name="hibernate.ogm.datastore.username" value="admin"/>
    <property name="hibernate.ogm.datastore.password" value="nnTdE2jPf4FV"/>
    <property name="hibernate.transaction.jta.platform"    value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM