I'm creating multiple objects and then i try to insert them into DB by session.flush() and then commit(). If one of those objects causes an error, the commit fails, and as the documentation says, i have to close my seesion.
BUT i dont want to lose all my other objects...
Is there a way to get from session the object that causes constraint violation exception , so that i could merge the rest of the objects into the new session and try to commit them again?
code example:
for(int i=0; i<10; i++){
session.save(person);
}
tx = session.beginTransaction();
try{
tx.commit();
}
catch(HibernateException e){
tx.rollback();
// in here i need to know which person object caused an constraint violation exception so that i can save all the other objects in another session....
session.close();
}
|