If anyone has a working example of a transaction rolling back properly could they please let me know.
I only need rollback to work for one transaction updating one database. All the examples on the web and in the Hibernate Documentation seem to follow this basic pattern:
Code:
Session sess = factory.openSession();
Transaction tx = null;
try {
tx = sess.beginTransaction();
// do some work
...
tx.commit();
}
catch (RuntimeException e) {
if (tx != null) tx.rollback();
throw e; // or display error message
}
finally {
sess.close();
}
I have tried these out and it doesnt seem to work for me. The way I am currently testing the rollback is by having an update that fails because of a foreign key association failed. However, frustratingly, the update is not being rolled back. The entry is still being made in the database and an exception is thrown.
Any help in this matter would be greatly appreciated.
Outlaw.