Db.tx() 事务下取值小记

技术分享

2018-07-20

830

0

遇到一个坑,然后....;懒得描述了,看代码吧:

@Before(Tx.class)
public boolean business() {

// do something with your business
Db.update("update table set status = '0' where id = 1");

// another business
anotherBusiness();

}

public void anotherBusiness() {

// do with your new business;

// this business need data with conditions updated in previous business just like (status != '0'),and can we get it ?
Record dbData = Db.findFirst("select * from table where status != '0' and id = 1");
// the answer is that we can`t get it; so how we fix it; change your update order in last business;

}


//fixed
@Before(Tx.class)
public boolean business() {

// do something with your business

// another business
anotherBusiness();

Db.update("update table set status = '0' where id = 1"); // and update last;

}




发表评论

全部评论:0条

云教务管理员

用IT武装教育!