Spring JPA - 没有事务集自动提交' true'

时间:2015-07-05 10:57:40

标签: hibernate jpa openjpa jpa-2.1

有没有办法在没有交易的情况下使用JPA自动提交?

的persistence.xml

statement 1

数据-config.xml中

code 2

CODE

<persistence-unit name="mytest" transaction-type="RESOURCE_LOCAL">
    <properties>
        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
    </properties>
</persistence-unit>

但是在会话终止之前我无法看到提交。我想按记录提交记录。

2 个答案:

答案 0 :(得分:0)

不,JPA中没有自动提交,它也没有多大意义,因为对实体的每次更改都是最终进入数据库的更改。使用自动提交,对属性的每次更改都将是一个事务。这是一个非常特殊的要求,不符合JPA的候选要求。

但您需要做的就是围绕entityManager.merge(user);

包装交易

答案 1 :(得分:0)

您可以尝试在persistence.xml中使用<property name="hibernate.connection.autocommit" value="true" />

有关autocommit属性的讨论,请参阅stackoverflow的this link以供参考。