I have some hibernate code and I want my code run in 1 transaction let me explain in code
public void changeBranch(Branch branch) throws DatabaseException {
//some code
humanDao.update(he);
superBranchUsername = branch.getFatherUsername();
int superBranchId = branchDao.getBranchIdByUserName(superBranchUsername);
BranchEntity superBranch = branchDao.load(superBranchId);
BranchEntity be = new BranchEntity();
setBranchEntity(be, he, pkId, bname, confirmed, level, studentCount, uname, superBranch);
branchDao.update(be); // update kardane jadvale Branch va Set kardane Human motenazer be on
//some code
}
Both humanDao.update(he);
and branchDao.update(be);
run in transaction handle by My GenericDAO that humanDao and branchDao are inherited from it.
but I want this block of code (wrote above) to also run in a transaction!! How can I get to Hibernate to do this?
I find how should I fix it if I new session in changeBranch(Branch branch)
and pass this session as a parameter to my DAO my problem solved