I got some very strange behaviour using session.update() and session.flush().
Look at the following example code (o1 and o2 are different objects):
Code:
Object o1 = session.load(Class, 1)
Object o2 = session.load(Class, 2)
o1.setExample("1")
o2.setExample("2")
session.update(o1);
session.flush();
session.rollback();
session.update(o2);
session.flush();
session.commit();
I saw in the DEBUG log messages, that the changes of o1 AND o2 will be written to the database after the first flush(). So the second flush() does nothing. That means, that the rollback after the first flush() restores both objects on the database.
Looking at the code I had expected, that o2 will be changed after executing the code, cause session.update(o2) is executed after the rollback and before the commit.
What can I do, that an object is not written to the database, before I have called session.update(object)?
Thanks in advance.