Hi guys!
I have some problems here!!
My application is multiuser and all of them share the same hibernate session (for memory reasons)
I process some objects in batch process (inserts and updates, some of them with merge) in the same transaction.
It's very strange but....
The problem is when, for example, i try to insert a new row in any table (really master/detail table and update another row in other table) and it throws a constraint exception. I catch this exception, I rollback current transaction and show the message. I can't clear the session because the users share the same session!!!!!
Then... i try to execute a simple update but the application try to execute all again!!! not only the update sentences!!! Of course it throws the previous constraint exception again!!!
I don't want this happen again. I want that it executes only te update sentenses ignoring previous inserts and updates...
I thought this would be done automatically WITH ROLLBACK, but no, it does not.
here my method
Code:
public boolean saveOrUpdateAndDelete(List<TransactionalOperation> list) {
boolean result = false;
org.hibernate.Transaction tx = null;
try {
tx = session.beginTransaction();
System.out.println("Se abrio la transaccion");
int i;
for (i = 0; i < list.size(); i++) {
// System.out.println("Es " + list.get(i).getClass());
if (list.get(i).getEntity() != null) {
if (!list.get(i).executeOperation()) {
// executeOperation execute update, insert or detele
System.err.println("aca lanzo el error");
throw new HibernateException(errorMsg);
}
}
}
tx.commit();
System.out.println("se cerro la transaccion");
result = true;
} catch (ConstraintViolationException e) {
tx.rollback();
System.out.println("Error de Constraint " + e.getSQLException().getNextException().getMessage());
errorMsg = "ViolaciĆ³n de integridad de datos en " + this.getConstraintTable(e.getSQLException().getNextException().getMessage());
System.out.println("rollback");
} catch (HibernateException ex) {
if (ex.getCause() != null && ex.getCause() instanceof ConstraintViolationException) {
errorMsg = "ViolaciĆ³n de integridad de datos.";
} else {
errorMsg = ex.getMessage();
}
tx.rollback();
System.out.println("rollback global");
}
return result;
}
Thanks
Nicolas