JPA - JTA事务类型不会保留更改

时间:2015-09-09 11:13:02

标签: java jpa eclipselink jpa-2.0 oc4j

我正在使用JTA,我的persistence.xml如下

<?xml version="1.0" encoding="UTF-8" ?>
<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_1_0.xsd" version="1.0"
             xmlns="http://java.sun.com/xml/ns/persistence">
  <persistence-unit name="test" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/testDS</jta-data-source>
    <class>test.entity.Employees</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
    <properties>
      <property name="eclipselink.target-server" value="OC4J"/>
      <property name="javax.persistence.target-database" value="Oracle"/>
      <property name="javax.persistence.logging.parameters" value="TRUE"/>
    </properties>
  </persistence-unit>
</persistence>

当我使用JTA时,我没有EntityTransaction。

Java代码段

    Employees emp = new Employees();
    emp.setEmpNumber(empPOJO.getEmpNumber());
    final EntityManager em = getEntityManager();
    try {           
            em.merge(vehicleInspection);            
    } finally {
        if (em != null && em.isOpen()) {
            em.close();
        }
    }
}

但是我无法在数据库中保留更改。这是因为没有提交吗?

1 个答案:

答案 0 :(得分:1)

启用交易后,您必须正确处理它们。 有关详情,请查看此wikyJPA sample code