-->
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 causes session close
PostPosted: Tue Jan 08, 2008 3:36 am 
Newbie

Joined: Wed Oct 25, 2006 8:45 am
Posts: 9
I'm using Hibernate JPA. In my application, if I do an entityManager.getTransaction().rollback(), it causes all objects retrieved from that entity manager to be detached, so that if I try to access a lazy-fetched collection after the rollback, it causes an error. Is this intentional? Is there a way to keep an in-memory object attached across a rollback?

Versions:
hibernate-3.2
hibernate-annotations-3.3.0.GA
hibernate-entitymanager-3.3.1.GA


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 08, 2008 5:01 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
I would say this behavior is indeed intentional. Entities are bound to the session for the lifetime of the transaction. Rolling back the transaction is just another way of terminating a transaction. For this reason I think the behavior is consistent.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 09, 2008 3:26 am 
Newbie

Joined: Wed Oct 25, 2006 8:45 am
Posts: 9
The entities in question were retrieved before the transaction was begun, so it seems inconsistent that they should be influenced by a transaction that started later. Also, they are not cleared if the transaction is committed, only if it's rolled back.

1. retrieve entity A
2. begin transaction
3. modify entity B
4. rollback transaction
5. entity A is detached.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 09, 2008 6:59 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This is as per the JPA spec. The reasoning is that when you rollback your transaction, you basically messed up with the session state (the objects are in a different state than the transaction / database). so the safe operation is to clear the entityManager (it is not closed).

_________________
Emmanuel


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.