-->
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.  [ 4 posts ] 
Author Message
 Post subject: Rollback and the first level cache
PostPosted: Mon Apr 04, 2005 9:37 am 
Newbie

Joined: Mon Dec 15, 2003 3:34 pm
Posts: 18
Hi everyone

Assuming I have a bean called Person with an assigned id, the following code will throw a NonUniqueObjectException:

Code:
Transaction tx = session.beginTransaction();

Person person1 = new Person();
person1.setId(new Integer(1));
session.save(person1);

tx.rollback();

Person person2 = new Person();
person2.setId(new Integer(1));
session.save(person2); // throws NonUniqueObjectException


Shouldn't rollback() evict person1 from the first level cache? The only solution I found so far is to manually evict person1 calling session.evict(person1) or session.clear().

Comments from the Hibernate Team would be welcome.

Thanks in advance,
Gabriel.

_________________
Gabriel C. Oliveira
Sumersoft Technology, Brazil


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 04, 2005 12:13 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
for the moment persistent objects aren't transactionnal.
When ou call rollback, session is not going to get its previous state, you should discard the session and get a new one.

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 04, 2005 12:26 pm 
Newbie

Joined: Mon Dec 15, 2003 3:34 pm
Posts: 18
anthony wrote:
for the moment persistent objects aren't transactionnal.
When ou call rollback, session is not going to get its previous state, you should discard the session and get a new one.


Will it be a future feature?

It seems to me that such behavior compromises the concept of long "application transactions" as described in Hibernate in Action.

Why should we be able to open multiple transactions within the same session if this constraint leaves the session in a dirty state after a rollback?

Thank you.

_________________
Gabriel C. Oliveira
Sumersoft Technology, Brazil


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 04, 2005 2:21 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
HiA explains clearly that all database transactions in an application transaction should only read data, not write (set FlushMode.NEVER). Hence, there is no rollback - and besides, compensation would have to be done anyway, so you can as well include a fresh Session in your recovery process.


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

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.