-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: transaction.rollback() after saveOrUpdate
PostPosted: Wed Oct 17, 2007 9:51 am 
Newbie

Joined: Mon Sep 10, 2007 9:30 am
Posts: 12
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.