- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在事务回滚方面遇到问题,其中一个用 REQUIRES_NEW 注释的子事务被回滚,因为父事务被回滚。我很困惑,因为我曾认为 JTA/JPA 独立处理这些事务,因此一个事务的回滚不会影响另一个事务。我正在使用 Java 1.6.0_24、EJB 3.1、GlassFish 3.0.1、JPA 2、MS SQL Server(非 XA)2008、CMT。
下面的示例显示了本质:进程 EJB 在其自己的 TN 中在开始时调用审计器,执行 DB 操作但确定失败,设置回滚,然后在完成时调用审计器。 Auditor EJB 调用 JPA 以在单独的事务 (REQUIRES_NEW) 中创建审计记录,并且在事务成功时工作正常。该代码显示了一个通用的审计结构,省略了所有不必要的代码——泛型似乎是问题的一部分。
public interface ErrorDescriptor {
public String getName ();
}
public interface GenericAuditor<T extends ErrorDescriptor> {
public void log(T errorType);
}
public abstract class AbstractGenericAuditorImpl<T extends ErrorDescriptor>
implements GenericAuditor<T> {
}
public enum AuditType implements ErrorDescriptor {
BEGIN, FAILED;
public String getName() { return name(); }
}
public interface Auditor extends GenericAuditor<AuditType> {
// The absence of the following 2 lines causes the problem
@Override
public void log(AuditType errorType);
}
@Stateless
public class AuditorImpl
extends AbstractGenericAuditorImpl<AuditType>
implements Auditor {
@PersistenceContext ("EntityPersistenceManagement")
protected EntityManager entityManager;
@Override
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void log (AuditType e) {
ErrorEvent errorEvent = new ErrorEvent (); // entity
errorEvent.setName (e.getName());
entityManager.persist (errorEvent);
}
}
@Stateless
public class ProcessImpl implements Process {
@Resource private EJBContext ejbContext;
@EJB private Auditor auditor;
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void method1() {
auditor.log(AuditType.BEGIN);
// Perform series of actions including database ops
// Takes up to 1 minute
// Somethings happen that detects failure
ejbContext.setRollbackOnly ();
auditor.log(AuditType.FAILED);
}
}
问题是当 parent.method1() 被调用时,它会安静地进行,直到它确定失败并设置回滚。那时,第二次审计调用抛出客户的交易已中止,就好像它是当前交易的一部分而不是在单独的交易中一样。此外,第一个审计调用不会在数据库中放置任何数据——即使成功它也不会提交,直到父项提交(这正常吗?)这在单独的事务中应该是非 XA。
我读过许多声称交易是独立的文章,但是 this one建议嵌套事务在父事务提交之前不提交,如果父事务回滚,子事务也会回滚。如果那是真的,我不明白如何提交部分或状态工作,因为在提交最顶层的事务之前什么都不会提交。
JPA Config--我最初使用单个数据源,但后来切换到两个,但我没有发现任何差异。
<persistence-unit name="EntityPersistenceManagement" transaction-type="JTA">
<jta-data-source>jdbc/app1</jta-data-source>
<properties>
<property name="eclipselink.logging.level" value="INFO"/>
<property name="eclipselink.weaving.internal" value="false"/>
<property name="eclipselink.weaving" value="false"/>
<property name="eclipselink.weaving.fetchgroups" value="false"/>
<property name="eclipselink.weaving.changetracking" value="false"/>
<property name="eclipselink.weaving.lazy" value="false"/>
<property name="eclipselink.weaving.internal" value="false"/>
<property name="eclipselink.weaving.eager" value="false"/>
<property name="eclipselink.cache.shared.default" value="false"/>
<property name="eclipselink.cache.shared" value = "false"/>
<property name="eclipselink.query-results-cache" value="false"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
</properties>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<class>org.foo.entities.AppRecord</class>
<class>org.foo.entities.ErrorEvent</class>
谁能说回滚是否应该这样工作?也许这在 XA 下有所不同?
我已经上传了这个annotated transaction log在代码中查找控制点的 ** 条目。
已添加:这 second log具有 FINEST 级别的 EclipseLink。
编辑:我修改了代码以准确显示导致问题的原因并仅返回给一个持久性管理器。
最佳答案
此问题是 GlassFish 的错误 https://java.net/jira/browse/GLASSFISH-8319 ,在 v 3.1 中记录为已解决。
关于java - EJB JTA/JPA CMT 事务回滚影响子事务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17280724/
JTA 和本地事务有什么区别? 如果有一个示例可以展示何时使用 JTA 以及何时使用本地事务,那就太好了。 最佳答案 JTA 是用于管理 Java 事务的通用 API。它允许您以资源中立的方式启动、提
我正在使用 Atomikos 进行 JTA 事务。 我对 JTA 有以下设置: UserTransactionImp userTransactionImp = new UserTransactionI
已结束。此问题不符合 Stack Overflow guidelines .它目前不接受答案。 我们不允许提出有关书籍、工具、软件库等方面的建议的问题。您可以编辑问题,以便用事实和引用来回答它。 关闭
我想找到一种方法来应用带有 JTA @Transactional 注释的自定义拦截器。 我有一个带有 @Transactional 的方法,它是业务事务之一。在该方法中我想: 进行一些数据库操作 使用
我正在更新旧的应用程序,并尽可能少地重新编程。我创建了一个与旧页面类似的页面,其中仅包含一些测试数据,以确保我可以创建与 ejb/jpa 的链接,但我遇到了问题。我将发布 jsp、persistenc
本文整理了Java中com.arjuna.ats.internal.jta.tools.osb.mbean.jta.XAResourceRecordBean类的一些代码示例,展示了XAResource
我们将 JPA 1.0 用于基于 ORM 的操作,并且我们希望我们的应用程序拥有 JTA 数据源。我们只有 1 个数据库,我们的应用程序将连接到该数据库。 我们在 Controller 类中开始我们的
本文整理了Java中com.arjuna.ats.internal.jta.tools.osb.mbean.jta.XAResourceRecordBean.()方法的一些代码示例,展示了XAReso
本文整理了Java中com.arjuna.ats.internal.jta.tools.osb.mbean.jta.XAResourceRecordBean.getUid()方法的一些代码示例,展示了
我如何定义 在 persistence.xml 中? 我的项目在 Tomcat 6 和 Tomcat 7 中运行良好。 现在我正在使用 Struts 2 Spring 3.0.5 JPA 2 Jbos
我想为我正在处理的应用程序编写集成测试。它使用 JTA(多资源)并在应用程序服务器内运行。为这种情况编写自动化测试的最佳方法是什么?使用像 atomikos 这样的独立事务管理器,或者以某种方式利用应
我们正在使用 jboss 管理的 EntityMangerFactory 使用以下 spring bean 现在在我们的 spring bean 中,我们使用 @PersistenceContext
从 JTA 规范中,我了解到它仅用于调用线程的分布式事务(或支持)。这是否意味着事务不能跨越多个线程?还是取决于实现? 是否有任何 JTA 实现支持跨线程 XA? 谢谢! 最佳答案 您可以使用 Tra
本地交易和BMT相同吗? 我们需要 transactionManager 来进行本地事务吗? 我读到 transactionManager 对于本地事务将无效。这是正确的吗? JTA 是否为 CMT
我是 Spring 和 hibernate 新手,请帮忙, 我正在使用(Jboss 6.0 Final 作为服务器) org.springframework.transaction.jta.JtaTr
假设我有一个托管 bean 并且定义了一个 EntityManager。我想知道交易是如何运作的以及它们在各种不同情况下的表现如何。从文档中我了解到,flush()实际上用于覆盖提交上的延迟并立即执行
试图将我的头脑围绕在 JTA 上并任意选择 Bitronix 作为 impl,因为文档更容易获得(与 Atmikos 相反,Atmikos 让你注册并注册以获得 src/docs/jars/等等)。
我使用以下我在网上找到的代码 ( Here ) 作为 JTA 事务处理的示例: // Get a UserTransaction UserTransaction txn = new I
我有 2 个 MySQL 架构和各自的 MysqlXADataSource 配置如下 - @Bean(name = "sourceDataSource") @Primary public DataSo
我正在开发一个Web应用程序,我必须使用我从未使用过的JTA。我开始使用 EntityManager 但它似乎在这里不起作用。当我使用 EntityManager 时,我收到此消息: Only per
我是一名优秀的程序员,十分优秀!