java - is rollback possible in hibernate if one transaction fails among multiple transaction to different tables? -
i have 1 method :
// methods private void transform(transformlist transformlist) { tablea ta = transformlist.gettablea(); tableb tb = transformlist.gettableb(); tablec tc = transformlist.gettablec(); daoobj.savea(ta); daoobj.saveb(tb); daoobj.savec(tc); }
now,
//savea mehtod public void savea(tablea ta) { session session = context.gethibernatesession(); seek { if(session != null) { transaction tx = session.begintransaction(); tx.begin(); session.merge(ta); tx.commit(); } }catch (exception e) { tx.rollback(); throw new someexception(e.getmessage()); } finally{ if (session != null) { session.clear(); } } }
similarly,
//saveb mehtod public void saveb(tableb tb) { session session = context.gethibernatesession(); seek { if(session != null) { transaction tx = session.begintransaction(); tx.begin(); session.merge(tb); tx.commit(); } }catch (exception e) { tx.rollback(); throw new someexception(e.getmessage()); } finally{ if (session != null) { session.clear(); } } }
and,
//savec mehtod public void savec(tablec tc) { session session = context.gethibernatesession(); seek { if(session != null) { transaction tx = session.begintransaction(); tx.begin(); session.merge(tc); tx.commit(); } }catch (exception e) { tx.rollback(); throw new someexception(e.getmessage()); } finally{ if (session != null) { session.clear(); } } }
now while calling 'transform' method, if savea , saveb method success , exception occurs in savec method, possible rollback tablea , tableb records (which committed already) along tablec records?
no. you'll have move transaction handling @ to the lowest degree 1 level higher: create transaction, , phone call savea(), saveb() , savec() within transaction. don't handle transactions within save methods.
of course, 1 possibility. there frameworks, spring, help manage transactions.
java hibernate
No comments:
Post a Comment