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.