DB2 EJB / JPA不回滚

时间:2014-05-12 20:44:13

标签: java jpa jboss

我正在用JBoss6.1 +中的CMT试验一个非常奇怪的行为并访问zos / 390 DB2。

环境是:

  • JBoss 6.1+
  • Linux Red Hat
  • 在ZOS 390中运行的DB2
  • EJB3 / JPA2

事务只是不使用SystemExceptions回滚。 我尝试过BMT,但也很不舒服。 我的BMT代码如下:

@Stateless
@LocalBean
@TransactionManagement(TransactionManagementType.BEAN)
public class ManterPortabilidadeBean
    implements PortabilidadeService {

    @Inject
    private UserTransaction tx;

    @Override
    public void incluirPortabilidade(...) {
        try {
        tx.begin();

            //insert into database          
        daoPortabilidade.incluir(portabilidade);

        if (1==1) 
            throw new EJBException("Bingo");

        tx.commit();
        } catch (Exception e) {
        try {
            tx.rollback();
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        } 
    }
}

好吧,记录在数据库中!!!难以置信!!! EJB容器完全忽略,什么都不做。

这是CMT代码:

@Stateless
@LocalBean
@TransactionManagement(TransactionManagementType.CONTAINER)
public class ManterPortabilidadeBean
    implements PortabilidadeService {

    @Override
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public void incluirPortabilidade(...) {
        //insert into database          
        daoPortabilidade.incluir(portabilidade);

        if (1==1) 
            throw new EJBException("Bingo");
    }
}

我认为DB2是自动提交的,如autocommit = true,但是autocommit的配置信息是false,请参阅下面的persistence.xml:

<persistence-unit name="gecDS" transaction-type="JTA">
    <jta-data-source>java:/jdbc/DB2SigecDS</jta-data-source>
    <properties>
        <property name="hibernate.dialect"value="org.hibernate.dialect.DB2390Dialect" />
        <property name="hibernate.default_schema" value="GEC" />
        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.format_sql" value="true" />
        <property name="hibernate.connection.isolation" value="2" />
        <property name="hibernate.connection.autocommit" value="false"/>
        <property name="javax.persistence.jdbc.driver" value="com.ibm.db2.jcc.DB2Driver" />
    </properties>
</persistence-unit>

我standalone.xml我有这个数据源配置:

<datasource jta="false" jndi-name="java:/jdbc/DB2SigecDS" pool-name="jdbc/DB2SigecDS" enabled="true">
    <connection-url>jdbc:db2://************</connection-url>
    <driver-class>com.ibm.db2.jcc.DB2XADataSource</driver-class>
    <driver>db2</driver>
    <security>
        <user-name>*******</user-name>
        <password>*******</password>
    </security>
</datasource>

任何想法,配置??? THX

1 个答案:

答案 0 :(得分:0)

我发现了一个奇怪的问题。 只是配置!!!

在datasource属性中,“jta”必须为true(thx Aramburu),我正在使用XADatasource:

<persistence-unit name="gecDS" transaction-type="JTA">
    <jta-data-source>java:/jdbc/DB2SigecDS</jta-data-source>
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.DB2390Dialect" />
        <property name="hibernate.default_schema" value="GEC" />
        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.format_sql" value="true" />
        <property name="hibernate.connection.isolation" value="2" />
        <property name="hibernate.connection.autocommit" value="false"/>
        <property name="javax.persistence.jdbc.driver" value="com.ibm.db2.jcc.DB2XADataSource" />
    </properties>
</persistence-unit>


<datasource jta="true" jndi-name="java:/jdbc/DB2SigecDS" pool-name="jdbc/DB2SigecDS" enabled="true">
    <connection-url>jdbc:db2:**************</connection-url>
    <driver-class>com.ibm.db2.jcc.DB2XADataSource</driver-class>
    <driver>db2</driver>
    <security>
        <user-name>???????</user-name>
        <password>???????</password>
    </security>
</datasource>

Thx朋友