CMT交易 [英] CMT transactions

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

问题描述

我的另一个问题...
如果我有一个无状态服务(无状态会话Bean)作为立面(例如GlobalService)哪些方法调用其他几个服务(再次是SLSB,说FooService和BarService): / p>

  @Stateless 
@Remote(GlobalService.class)
@TransactionManagement(TransactionManagementType.CONTAINER)
public class GlobalServiceBean实现GlobalService {
private Logger log = Logger.getLogger(GlobalServiceBean.class);

@EJB
private FooService fooService;

@EJB
私人BarService barService;

public void createFoo(Foo foo,Bar bar)throws WrappedGoneBadException {
fooService.create(foo); // bang here
barService.create(bar); // no bang here

FooService中的所有方法(以及BarService,看起来几乎相同) )注释为需要新的交易:

  @Stateless 
@Remote(FooService.class)
@ TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public class FooServiceBean实现FooService {
public Foo save(Foo foo){
... // exception here假设FooServiceBean持续存在一些类型为Foo的对象,在此期间,未检查的异常(DuplicateKeyException)将会被抛出这会影响周围交易被回滚还是被忽略?Bar将被创建?



我的初步想法是不会影响交易,但Jboss证明我错了...



这是我们可以期待的行为,我错了,如果是...如何隔离他们两个:Foo引起一个例外,显然没有保存,但Bar被保存?

解决方案

这是不当的异常处理,导致客户在继续第二次交易之前停止了这个世界。


One more question from my side ... If I have a stateless service (Stateless Session Bean) as facade (say GlobalService) which methods invokes several other services (again SLSBs, say FooService and BarService):

@Stateless
@Remote(GlobalService.class)
@TransactionManagement(TransactionManagementType.CONTAINER)
public class GlobalServiceBean implements GlobalService{
private Logger log = Logger.getLogger(GlobalServiceBean.class);

@EJB
private FooService fooService;

@EJB
private BarService barService;

public void createFoo(Foo foo, Bar bar) throws WrappedGoneBadException{
          fooService.create(foo); // bang here 
              barService.create(bar); // no bang here

All methods at FooService (as well as BarService, which looks pretty much the same) annotated as requiring a new transaction:

@Stateless
@Remote(FooService.class)
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public class FooServiceBean implements FooService{
   public Foo save(Foo foo){
     ... // exception here

Presumed FooServiceBean persists some objects of type 'Foo' and during this, an unchecked exception (DuplicateKeyException) will be thrown does this affect the 'surrounding' transaction to be rolled back or will it be ignored and Bar will be created?

My initial thought have been, it will not affect the transaction but Jboss proved me wrong ...

Is this the behaviour one can expect, am I wrong and if so ... how to isolate the both of them: Foo to cause an exception and obviously not saved but Bar to be saved?

解决方案

Shame on me ... it was the inappropriate Exception Handling which causes the client to stop the world prior to continuing the second transaction.

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

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