Data are not visible at support transation block

假装没事ソ 提交于 2019-12-12 00:25:14

问题


My method calls are like follow.

@TransactionAttribute(TransactionAttributeType.SUPPORTS
void M1() {
   M2();
   M3();
}

@TransactionAttribute(TransactionAttributeType.REQUIRED)    
void M2(){
   //saving x on data base
}

@TransactionAttribute(TransactionAttributeType.SUPPORTS)
void M3(){
    //accessing x from data base
}

The issue is, some times value x is unavailable at method M3.

Can any body say whats the possible issue here ?


回答1:


There are two cases in your example, result is depending on whether is transaction already started in M1 or not, let me show you how it works

public void M1() {
   //transaction doesn't exist now
   M2();
   //transaction context has been created and ended due to REQUIRED attribute
   M3(); 
   //now you see result in DB because it was commited in M2s transaction 
}

public void M1() {
   //transaction already exists from method which called M1
   M2(); 
   //joins the transactional context
   M3();  //gets attached to the same context
   // and now whole transaction gets commited and only now you can be sure that you can read from DB safely
}

I hope it's helpful for you, solution would be marking M1 REQUIRED as well.



来源:https://stackoverflow.com/questions/20947979/data-are-not-visible-at-support-transation-block

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