数据在支持交换块中不可见 [英] Data are not visible at support transation block

查看:136
本文介绍了数据在支持交换块中不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的方法调用如下。

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

@TransactionAttribute(TransactionAttributeType.REQUIRED)
void M2(){
//在数据库上保存x
}

@TransactionAttribute(TransactionAttributeType.SUPPORTS)
void M3(){
//从数据库访问x
}

问题是,某些时候,值x在方法M3中不可用。



任何身体都可以说出可能出现的问题?

解决方案

你的例子有两种情况,结果取决于是否在 M1 中开始交易,让我向您展示如何运作

  public void M1(){
// transaction现在不存在
M2();
//事务上下文由于REQUIRED属性
M3();
//现在您在DB中看到结果,因为它在M2s事务中被提交
}

public void M1(){
//事务已经存在于称为M1的方法中
M2();
//加入事务上下文
M3(); //附加到相同的上下文
//,现在整个事务被提交,只有现在你可以确定你可以从DB安全地读取
}

我希望对您有帮助,解决方案也将标记 M1 。 >

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 ?

解决方案

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.

这篇关于数据在支持交换块中不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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