请问hibernate的两个方法如何用事务关联到一起啊?
比如我DAO层有两个方法用于转账操作,一个是转出的方法,一个是转入的方法
转出帐户方法:
public void subMoney(int subAccountID,int exchangeMoney){ Session session = this.getSession(); Transaction tx = session.beginTransaction(); String hql = "update CCBAccountPO set property = property - " + exchangeMoney +" where id = " + subAccountID; Query query = session.createQuery(hql); query.executeUpdate(); tx.commit(); }
public void addMoney(int addAccountID,int exchangeMoney){ Session session = this.getSession(); Transaction tx = session.beginTransaction(); String hql = "update ICBCAccountPO set property = property +" + exchangeMoney + " where id = " + addAccountID; Query query = session.createQuery(hql); query.executeUpdate(); tx.commit(); }