I want to update some of my tables in the database and I want all these works to be performed in one transaction, first of all, I delete some record in branchbuildin (Table) and insert a new one after this action. A problem occurred when I insert and enter with that the same name of the building and branch_fk (because of this I have this restriction in this table (uniqueConstraints = {@UniqueConstraint (columnNames = {"buildingname", "branch_fk"})})), but when I donβt know, t use the session sleep mode and use normal JDBC transaction. I do not have this problem.
List<Integer> allBranchBuilding = branchBuildingDao.getAllBranchBuildingID(pkId, sess);
for (Integer integer : allBranchBuilding) {
branchBuildingDao.delete(integer, sess);
}
Address myAdr = new Address();
setAddress(myAdr, centralFlag, city, latit, longit, mainstreet, remainAdr, state);
BranchBuildingEntity bbe = new BranchBuildingEntity();
setBranchBuildingEntity(bbe, be, myAdr, city, centralFlag, latit, longit, mainstreet, buildingName, remainAdr, state, des);
branchBuildingDao.save(bbe, sess);
I get my session with the first method:
Session sess = null;
sess = HibernateUtil.getSession();
Transaction tx = sess.beginTransaction();