Hibernate - Commit one item at a time within a list (ignoring the failed ones) -
how can commit 1 item @ time in hibernate. have arraylist of items. need save of them db.. in case records fail due "being dirty".. m ok ignore , move on other ones.
tried committing records in loop below
session.begintran.. loop { try { session.update(item) session.commit() } catch(exception e) { //log & ignore } }
this gave me "nested tran not possible" error..
moved begintran inside loop.. m observing is.. if first record fails, each commit tries update same record again though {item} object gets next 1 list, within loop
loop { try { session.begintran session.update(item) //eventhough item object gets loaded within loop.. every time commit executed, trying save first failed record again. session.commit() } catch(exception e) { //log & ignore } }
hibernate exceptions not recoverable. leave session in inconsistent state, making further usage unreliable. exception thrown session, session must discarded.
use single session per transaction.
if session throws exception, including sqlexception, rollback database transaction, call session.close() , discard session instance. methods of session not leave session in consistent state. no exception thrown hibernate can treated recoverable. ensure session closed calling close() in block.
Comments
Post a Comment