I think I got it now. This seems to work:
Code:
Transaction tx = HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
User user1 = userDAO.findById(new Integer(1), false);
user1.setFirstname("Jane");
userDAO.flush();
Savepoint savepoint = userDAO.setSavepoint("my_savepoint");
user1.setFirstname("John");
userDAO.flush();
userDAO.rollbackSavepoint(savepoint);
tx.commit();
Resulting firstname in the database is "Jane". I guess I simply lacked knowledge of the flush mechanism.
The savepoint methods in the DAO looks as followed:
Code:
private Savepoint savepoint;
public Savepoint setSavepoint(final String savePoint)
{
getSession().doWork(new Work()
{
public void execute(Connection connection) throws SQLException
{
savepoint = connection.setSavepoint(savePoint);
}
});
return savepoint;
}
public void rollbackSavepoint(final Savepoint savepoint)
{
getSession().doWork(new Work(){
public void execute(Connection connection) throws SQLException
{
connection.rollback(savepoint);
}
});
}
Thanks for your support. I hope this is how it it meant to be used.
The Session.clear() thing isn't quite what I need. Too powerful you could say. Since some not yet performed operations might be wanted while others might not be. So sadly, clearing everything isn't an option...