-->
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.  [ 2 posts ] 
Author Message
 Post subject: Saving the same object in two sessions?
PostPosted: Tue Oct 21, 2003 11:46 am 
Newbie

Joined: Sun Oct 12, 2003 6:33 pm
Posts: 7
I have the following problem, in my application from time to time I retrieve objects from one (local) database and store them in another (remote) database.

Thus I have created two session objects, localSession and remoteSession, and proceeded the following way:

String query = ... // some query
List matches = localSession.find( query );
for ( Iterator it = matches.iterator(); it.hasNext(); )
{
Object match = it.next();
remoteSession.save( match );
localSession.delete( object );
}

However it seems two objects cannot be shared by the same session, or at least two collections referenced by the same object? If this is true, what would be a correct approach to this problem?

Thank you very much.

Melk


Top
 Profile  
 
 Post subject: Re: Saving the same object in two sessions?
PostPosted: Wed Oct 22, 2003 4:34 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Melk wrote:
However it seems two objects cannot be shared by the same session

Correct
Melk wrote:
If this is true, what would be a correct approach to this problem?

A object can be evicted from a session (session.evict(Object).
Code:
String query = ... // some query
List matches = localSession.find( query );
Object match;
for ( Iterator it = matches.iterator(); it.hasNext(); ) {
  match = it.next();
  localSession.evict(match);
  remoteSession.save(match);
  remoteSession.evict(match);
  localSession.delete(match);
}


But this isn't efficient (particularly if match has lazy collections).
The other way is to copy the object.

You may also have a look at the replicate() method of Hibernate 2.1 but I don't know it's behavior.

_________________
Emmanuel


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