-->
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: object deleted in multiple sessions
PostPosted: Thu Jan 08, 2004 12:17 pm 
Newbie

Joined: Thu Jan 08, 2004 12:05 pm
Posts: 14
Hi!

Anyone have any idea what is the best aproach for this situation :
I have to hibernate sessions, S1 and S2, and I load two objects with the same primary key, O1 loaded by S1 and O2 loaded by S2. The problem appear when I delete first O1 and then O2, as hibernate throw an exception if the coresponding row from database isn't there anymore.

How do you guys threat situations like this ? does hibernate provide a way to handle this or you handle this outside hibernate ?

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2004 12:54 pm 
Newbie

Joined: Thu Jan 08, 2004 12:05 pm
Posts: 14
Here is code snippet
Code:
   Session ses1 = sf.openSession();
   Session ses2 = sf.openSession();
   UserRole ur1 = (UserRole) ses1.load(UserRole.class, id);
   UserRole ur2 = (UserRole) ses2.load(UserRole.class, is);

   Transaction t2 = ses2.beginTransaction();
   Transaction t1 = ses1.beginTransaction();

   ses1.delete(ur1);
   t1.commit();
   ses1.close();

   ses2.delete(ur2);
   t2.commit();
   ses2.close();


[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 09, 2004 11:37 am 
Regular
Regular

Joined: Mon Nov 24, 2003 6:36 pm
Posts: 105
why do you need to load the 2 classes in diff sessions?
Are they different databases?

why not
User user = (User)sess.load(object1.class, key);
sess.delete(user)
user = sess.load(object2.class,key)
sess.delete(user)
tx.commit?

--James


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 12, 2004 8:05 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Try to use <version> tag. It may raise a staleObjectException. Not sure however (interested by the result).

_________________
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.