-->
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.  [ 7 posts ] 
Author Message
 Post subject: Deleted persistant object
PostPosted: Thu Nov 24, 2005 8:21 am 
Newbie

Joined: Wed Mar 09, 2005 11:32 am
Posts: 18
Hello.

When I have an object I just loaded using hibernate and after I load it was

deleted by another session (and commited there), do I now have a

reference to Null or just a transient object?

what will happen when I'll invoke a get() on one of its methods?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 24, 2005 2:35 pm 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
  1. Session A loads row x into object X.
  2. Session B loads row x into object X and deletes it and commits this change.


Session A knows nothing about the delete and assumes, that row x still exists in the DB. Every DB access for row x in Session A, let's say if X is a proxy, is likely to throw an exception.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 24, 2005 5:14 pm 
Newbie

Joined: Wed Mar 09, 2005 11:32 am
Posts: 18
But if am using isolation level 2 (read commited) shouldnt I see the change?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 24, 2005 5:31 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Not unless you detach the object after every read, or at least after every transaction. As I understand it, isolation levels do not affect hibernate's session cache, only the jdbc connection.

The "Transactions and Concurrency" section of the ref docs is pretty thorough.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 24, 2005 9:24 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
you have to call session.flush() (or session.refresh()) for synchronize your session with database (with commited state from another users) - this is same for every application, no only for hibernate - you have to see state in database


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 27, 2005 6:09 am 
Newbie

Joined: Wed Mar 09, 2005 11:32 am
Posts: 18
10x alot,

Now how can I know when a persistant object is no longer exist?

now Im doint refresh() and using the exception received.

Is there a better way?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 27, 2005 3:56 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
Quote:
Now how can I know when a persistant object is no longer exist?


you can try session.refresh(0 and get object again with session.get - get return null if object doesn't exists


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.