Omer-Pitou
asked on
Hibernate Not Rolling Back When something fails in a stored procedure
Hello Sirs,
I noticed something very strange. I have a MySQL stored procedure structured as follows:
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
RESIGNAL;
END;
SET SESSION sql_mode='';
START TRANSACTION;
COMMIT;
In my hibernate.cfg.xml, I set autoCommit to false.
On top of that my DAO calling the SP looks like this:
public boolean runBillingCycle(TiersContr at data) {
Session session = null;
Transaction tx = null;
try {
session = FinanceHibernateUtil.getSe ssionFacto ry().openS ession();
tx = session.beginTransaction() ;
session.doWork((Connection cnctn) -> {
String sql = "{CALL erp_partners_billing_cycle (?,?,?,?)} ";
CallableStatement stmt = cnctn.prepareCall(sql);
stmt.setInt("p_companyID", data.getCompanyID());
stmt.setInt("p_periode", data.getPeriode());
stmt.setString("p_majuser" , data.getMajUser());
stmt.setString("p_typetier s", data.getTypeTiers());
stmt.execute();
});
tx.commit();
} catch (Exception e) {
FinanceHibernateUtil.rollb ackTransac tion(tx);
MyExceptionUtil.handle(nul l, e);
return false;
} finally {
FinanceHibernateUtil.close Session(se ssion);
}
return true;
}
What can the reason for Hibernate or MySQL to not rolling back tables updated before in the same transaction when something goes wrong?
I am looking forward to hearing from you.
I noticed something very strange. I have a MySQL stored procedure structured as follows:
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
RESIGNAL;
END;
SET SESSION sql_mode='';
START TRANSACTION;
COMMIT;
In my hibernate.cfg.xml, I set autoCommit to false.
On top of that my DAO calling the SP looks like this:
public boolean runBillingCycle(TiersContr
Session session = null;
Transaction tx = null;
try {
session = FinanceHibernateUtil.getSe
tx = session.beginTransaction()
session.doWork((Connection
String sql = "{CALL erp_partners_billing_cycle
CallableStatement stmt = cnctn.prepareCall(sql);
stmt.setInt("p_companyID",
stmt.setInt("p_periode", data.getPeriode());
stmt.setString("p_majuser"
stmt.setString("p_typetier
stmt.execute();
});
tx.commit();
} catch (Exception e) {
FinanceHibernateUtil.rollb
MyExceptionUtil.handle(nul
return false;
} finally {
FinanceHibernateUtil.close
}
return true;
}
What can the reason for Hibernate or MySQL to not rolling back tables updated before in the same transaction when something goes wrong?
I am looking forward to hearing from you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks