Hi,
I have a question regarding the way tx.rollback() works. In the following code, I create a new message and it persists to the database when I commit. In the second transaction I change the value and then roll back, so it doesn't save the change to the database. What I'm looking for is to restore the message object back to the original value before the transaction started. Anyone know of a good way to do that in the same session, without doing another select?
Code:
Session s = sessions.openSession();
Transaction tx = s.beginTransaction();
Message m = new Message("This message should persist!");
try {
s.saveOrUpdate(m);
} finally {
tx.commit();
}
tx = s.beginTransaction();
try {
m.setText("This message is transient!");
s.saveOrUpdate(m);
} finally {
tx.rollback();
}
// m still has the 'rolled back' value at this point
s.close();