简体   繁体   English

Jboss EAP 7 CDI JTA @交易记录

[英]Jboss EAP 7 CDI JTA @Transactional

I am struggling to understand how I am supposed to deal with JTA and CDI running on a Jboss EAP 7 instance. 我正在努力了解应该如何处理在Jboss EAP 7实例上运行的JTA和CDI。 I can get a transaction manually by injecting a UserTransaction object coming from the container but when I annotate the method with the @Transactional I get an exception regarding no transaction available.... My question is. 我可以通过注入来自容器的UserTransaction对象来手动获得事务,但是当我使用@Transactional注释方法时,出现了关于没有可用事务的异常。...我的问题是。 Is there any config missing? 是否缺少任何配置? I read briefly that maybe I should create an interceptor myself in order to make it work, but I haven't found any consistent example... 我简要阅读了一下,也许我应该自己创建一个拦截器以使其起作用,但是我没有找到任何一致的示例...

In a default JEE container-managed environment, only enterprise beans (usually @Stateless beans are used) are transactional. 在默认的JEE容器管理的环境中,仅企业bean(通常使用@Stateless bean)是事务性的。 Once you enter such a bean from outside, the transaction will be opened. 从外部输入这样的bean后,交易将被打开。 With the @javax.transaction.Transactional annotation you can control the behavior of the transactions, but this is not necessary in default case. 使用@javax.transaction.Transactional批注,您可以控制事务的行为,但是在默认情况下这不是必需的。

Example bean: 示例bean:

@Stateless
public MyBean {
   public void withinTransaction() {
     System.out.println("i'm running within a transaction");
   }
   @Transactional(TxType.NOT_SUPPORTED)
   public void outsideTransaction() {
     System.out.println("no transaction available...");
   }
}
  • If you call MyBean.withinTransaction from a Servlet (eg via REST), a new transaction is created (if not already present). 如果从Servlet调用MyBean.withinTransaction (例如,通过REST),则会创建一个新事务(如果尚不存在)。
  • If you call MyBean.outsideTransaction , no transaction will be created. 如果调用MyBean.outsideTransaction ,则不会创建任何事务。
  • If you call this.outsideTransaction() from withinTransaction , you will still have the transaction available in outsideTransaction (because the interceptors are only bound to the bean boundaries) 如果调用this.outsideTransaction()withinTransaction ,您仍然可以在现有的交易outsideTransaction (因为拦截器只绑定到bean边界)
  • If you call this.withinTransaction() from outsideTransaction no new transaction is created (because the interceptors are only bound to the bean boundaries) 如果调用this.withinTransaction()outsideTransaction没有新的交易产生(因为拦截器只绑定到bean边界)
  • If outsideTransaction would be part of a second bean AnotherBean , which @Inject s MyBean , and you call MyBean.withinTransaction , then a new transaction will be created (if not already present). 如果outsideTransaction将是第二个bean AnotherBean@InjectMyBean ,并且您调用MyBean.withinTransaction ,则将创建一个新事务(如果尚不存在)。 Because you cross bean boundaries between AnotherBean.outsideTransaction and MyBean.withinTransaction . 因为您跨越了AnotherBean.outsideTransactionMyBean.withinTransaction之间的bean边界。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM