Glassfish:JTA / JPA交易没有回滚 [英] Glassfish: JTA/JPA transaction not rolling back

查看:160
本文介绍了Glassfish:JTA / JPA交易没有回滚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Oracle数据库运行Glassfish 3.1.1,并且遇到一个问题,事务没有回滚,而只在一个特定的环境中。相同的应用程序在其他机器上按预期工作。但是,同一台机器上的两个独立的Glassfish域将受到影响。

I am running Glassfish 3.1.1 with an Oracle database and have run into an issue with transactions not rolling back, but only on one specific environment so far. The same application works as expected on other machines. However, two separate Glassfish domains on the same machine are impacted.

在受影响的环境中,与EJB内的容器管理的事务(CMT)有类似的结果抛出一个RuntimeException,以及一个具有 UserTransaction#rollback()的bean管理事务(BMT)。

Within the affected environment, I have similar results with both a container-managed transactions (CMT) inside an EJB that throws a RuntimeException, and a bean-managed transaction (BMT) with UserTransaction#rollback().

这两种情况,基本问题似乎是JDBC连接以某种方式仍然以autoCommit = true设置,即使有进行的JTA事务。

In both cases, the underlying issue appears to be that the JDBC connection is somehow still set with autoCommit = true even though there is a JTA transaction in progress.

我的EJB / CMT测试看起来像这样:

My EJB/CMT test looks like this:

@Named
@Stateless
public class TransactionTest { 

  @PersistenceContext
  EntityManager entityManager;

  @TransactionAttribute(TransactionAttributeType.REQUIRED)
  public void rollbackTest() {
    Foo foo = new Foo();
    entityManager.persist(foo);
    entityManager.flush();

    throw new RuntimeException("should be rolled back");
  }
}

我的BMT / UserTransaction测试是这样的: / p>

and my BMT/UserTransaction test is like this:

public void rollbackUtxTest() throws Exception {
    utx.begin();

    Foo foo = new Foo();
    entityManager.persist(foo);
    entityManager.flush();

    utx.rollback();   
}

当我调用任一方法时, INSERT INTO FOO即使交易被回滚,也被提交。

When I call either method, the INSERT INTO FOO is committed, even though the transactions were rolled back.

我缺少什么 - 也许我没有我的连接池/数据源设置不正确?

What am I missing - perhaps I don't have my connection pool / datasource is not set up right?

我使用OracleConnectionPoolDataSource作为数据源类名。有没有什么需要做的,以确保我的数据库连接参与JTA交易?

I'm using OracleConnectionPoolDataSource as the datasource class name. Is there something I need to do to ensure my database connections participate in JTA transactions?

更新1 我原以为这是一个问题, code> OracleConnectionPoolDataSource 但事实证明它不相关。

UPDATE 1 I originally thought this was an issue with OracleConnectionPoolDataSource but it turned out it was not correlated. The same exact pool configuration works on one environment but not the other.

更新2 明确指出,这不是一个EJB / CMT问题,但是一般的JTA问题。

UPDATE 2 Clarified that this is not specifically an EJB/CMT issue, but a general JTA issue.

更新3 添加了关于JDBC自动提交的信息。确认persistence.xml是正确的。

UPDATE 3 added info about JDBC autocommit. Confirmed that persistence.xml is correct.

推荐答案

看起来这可能是domain.xml的问题,可能是Glassfish bug

It looks like this may be an issue with domain.xml, possibly a Glassfish bug.

在persistence.xml中,我有

In persistence.xml, I have

< jta-data-源> JDBC / TEST< / JTA - 数据 - 源>

在domain.xml中,我有

In domain.xml, I have

<jdbc-resource pool-name="TEST_POOL" description="" jndi-name="jdbc/TEST"></jdbc-resource>

但没有相应的< resource-ref ref =jdbc / TEST > - 丢失或拼写错误。 (我相信我通过UI创建JNDI数据源结束了,实现名称是错误的,然后在domain.xml c> jdbc-resource 中修复JNDI名称在 resource-ref 中。

But no corresponding <resource-ref ref="jdbc/TEST"> - either missing or misspelled. (I believe I ended up in that state by creating the JNDI datasource through the UI, realizing the name is wrong, then fixing the JNDI name in domain.xml jdbc-resource by hand but not fixing it in resource-ref.

在这种情况下,我注入 EntityManager 仍然有效但不参与JTA事务,如果我修复domain.xml,它的工作原理如下。

In this case, my injected EntityManager still works but is not participating in JTA transactions. If I fix domain.xml, it works as expected.

这篇关于Glassfish:JTA / JPA交易没有回滚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆