代码之家  ›  专栏  ›  技术社区  ›  alfredopacino

Hibernate OGM不保留没有事务的实体

  •  0
  • alfredopacino  · 技术社区  · 7 年前

    我刚在另一台机器上重新安装了Eclipse,并导入了一个曾经工作的项目(它在MongoDB中保存了Entities) 没有 事务处理)。

    密码就是这个

        MyEntity ent = new MyEntity();
        ent.setTitle("title");
        EntityManager e = Persistence.createEntityManagerFactory("MongoPU").createEntityManager();
        e.persist(event);
    

    它 坚持 如果我提交一个Arjuna JTA事务,这个实体。 但是我想知道为什么这个代码以前也不用事务处理。

    坚持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="MongoPU" transaction-type="JTA">
            <provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider>
    
            <exclude-unlisted-classes>false</exclude-unlisted-classes>
    
            <properties>
                <property name="hibernate.transaction.jta.platform"
                    value="org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform" />
                <property name="com.arjuna.ats.jta.jtaTMImplementation"
                    value="com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple" />
                <property name="com.arjuna.ats.jta.jtaUTImplementation"
                    value="com.arjuna.ats.internal.jta.transaction.arjunacore.UserTransactionImple" />
                <property name="hibernate.ogm.datastore.create_database"
                    value="true" />
                <property name="hibernate.ogm.datastore.provider"
                    value="mongodb" />
                <property name="hibernate.ogm.datastore.database"
                    value="mongodata" />
                <property name="hibernate.ogm.mongodb.host"
                    value="127.0.0.1" />
                <property name="hibernate.ogm.mongodb.port" value="27017" />
            </properties>
        </persistence-unit> 
    
    </persistence>
    

    与休眠有关的POM部分

        <dependency>
                <groupId>org.hibernate.ogm</groupId>
                <artifactId>hibernate-ogm-core</artifactId>
                <version>5.1.0.Final</version>
            </dependency>
            <dependency>
                <groupId>org.hibernate.ogm</groupId>
                <artifactId>hibernate-ogm-mongodb</artifactId>
                <version>5.1.0.Final</version>
            </dependency>
            <dependency>
                <groupId>org.jboss.jbossts</groupId>
                <artifactId>jbossjta</artifactId>
                <version>4.16.6.Final</version>
            </dependency>
            <dependency>
                <groupId>javax</groupId>
                <artifactId>javaee-web-api</artifactId>
                <version>7.0</version>
                <scope>provided</scope>
            </dependency>
        <dependency>
          <groupId>javax.transaction</groupId>
          <artifactId>jta</artifactId>
          <version>1.1</version>
      </dependency>
    

    不确定它是否相关,但我很确定我在运行时从未收到过这个警告(请注意,我总是使用HibernateOgm5.1.0,对POM没有任何更改)

    WARNING: An illegal reflective access operation has occurred
    WARNING: Illegal reflective access by javassist.util.proxy.SecurityActions (file:/home/aantonio/.m2/repository/org/javassist/javassist/3.18.1-GA/javassist-3.18.1-GA.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
    WARNING: Please consider reporting this to the maintainers of javassist.util.proxy.SecurityActions
    WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
    WARNING: All illegal access operations will be denied in a future release
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   Davide D'Alto    7 年前

    我不知道它以前为什么会工作,但是OGM的要点是你应该在你的应用程序中使用事务划分。如果你不想使用它,你需要 flush() 准备好后的操作。

    您可以在Hibernate OGM文档中找到其他说明: On flush and transactions .