CMT transactions

六眼飞鱼酱① 提交于 2019-12-11 10:08:29

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/14462342/cmt-transactions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!