Hello,
I'm a little bit confused about flushing and transactions:
I need a strong transactional behaviour, but after saving an object, searching with a query and roll-back the current transaction, the saved object is still stored in the database.
Hibernate version: 3.2.5.ga
Code between sessionFactory.openSession() and session.close():
Code:
Transaction tx = session.beginTransaction();
Test test1 = new Test();
test1.setA("aaa");
session.saveOrUpdate(test1);
String statement = "from Test where id = :id";
Query query = session.createQuery(statement);
query.add("id", test.getId);
Test test2 = query.uniqueResult();
Test test3 = session.get("Test", test.getId);
tx.rollback();
test2 and test3 return the same content.
Looking into the database there is a new test-entry with the id. I thought rollback() should prevent this.
Is it right that this is the result of the query, which makes a session.flush()?
With "session.setFlushMode(FlushMode.COMMIT);" test2 is null, test3 returns the content of test1 and nothing is stored into the database.
Why are there different results? I need to get the same results with the different ways and the working rollback().
Do I have a wrong understanding or is this possible?
regards