无法更新catch子句java hibernate上的行

mmvthczy  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(192)

有这种情况,就有table master_balance 存储余额,创建余额的收费金额,然后在 try ,如果出现错误 catch 归还余额:
function charge()<--调用数据库上的存储函数,其中charge是余额(balance-amount)

PERFORM 1 FROM master_balance where externalkey = $1 and tenant_record_id = $2 for update;

UPDATE master_balance
set balance = balance - $3
where id = (select t.id from master_balance t where t.externalkey = $1 and tenant_record_id = $2 order by id desc limit 1)
returning balance into newbalance;

function return()<--调用数据库中的存储函数,返回余额(余额+金额)

PERFORM 1 FROM master_balance where externalkey = $1 and tenant_record_id = $2 for update;

UPDATE master_balance
set balance = balance + $3
where id = (select t.id from master_balance t where t.externalkey = $1 and tenant_record_id = $2 order by id desc limit 1)
returning balance into newbalance;

java 语:

try{
balance = charge(12, 1, 4);

//example balance is 5 after charge, and when i print the balance got 5 and the table updated with value 5

Invoice invoice = new Invoice();
invoice.setCurBalance(balance); //balance is 5

tx.commit() <--- error from here
}catch(Exception e)
{
back = return(12, 1, 4); //balance is 6

//try to print back, the value out is 6 but not updated on table
}

但我有这样的情况,收费后的金额,什么时候要抓,是返回正确的值却没有更新表,是抓子句不能做查询吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题