I've a question about flushing.  My data access block functionally maps to the following:
 
Session sess = factory.openSession();
Transaction tx;
try {
     tx = sess.beginTransaction();
     //do some work
     ...
     tx.commit();
}
catch (Exception e) {
     if (tx!=null) tx.rollback();
     throw e;
}
finally {
     sess.close();
}
That's it - more or less, except I using the OS in View pattern, and a ThreadLocal object to store the Tx object. 
 
Now, what's happening is that I find I have to call an explicit Session.flush() prior followed by a tx.rollback() if I don't want Sql statements to be issued for changes made to any persistent entities loaded prior to the Tx.rollback(). If I don't call session.flush(), I think the system ends up issuing the statements anyway, thererby invoking implicit transactions against the database and locking up my tables.
 
Is this behavior by design - having to call Session.flush() prior to a Tx.rollback()?  Shouldn't the statements buffer be obliterated in the event of a rollback?
 
I am using 2.0 and haven't moved to updates after that yet.
 
Sandeep.
 

Reply via email to