-->
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.  [ 3 posts ] 
Author Message
 Post subject: Replication mode does not cascade
PostPosted: Wed Jan 04, 2006 9:37 am 
Newbie

Joined: Thu Jul 21, 2005 5:37 am
Posts: 9
Location: Paris
Hello,

To keep my description short, I will use the classical Parent-Child example to explain my problem.

The two persistent classes, Parent and Child are linked with a bidirectionnal many-to-many relationship.
My use case is to try to replicate parents and children from one session (database A) to another (database B).

Here is a sample of the data I have in database A :
Code:
Table Parent     
-------------     
id   name         
1    John           
2    Susan       
                 
Table ParentChild       
------------------     
parent_id  child_id   
  1           1   
  1           2     
  2           1
  2           2

Table Child       
------------         
id    name     
1    Oliver
2    Paul   


And for the mapping, I have specified a cascade="replicate, evict" for the Parent-Child side of the relationship.

So, first I load the Parents and evict them from session A (which also evicts their children).
Then I simply try to replicate each parent and its children by
Code:
sessionB.replicate(parent1, ReplicationMode.LATEST_VERSION);
sessionB.replicate(parent2, ReplicationMode.LATEST_VERSION);


I assumed that, given the specified cascade attribute on the Parent-Child relationship, this would be sufficient to replicate parents along with their children.

Unfortunately, this does not work because the replication mode seems not to be cascaded, as you can see in the following session flush result :
Code:
INSERT INTO PARENT (1, 'John')
INSERT INTO CHILD (1, 'Oliver')
INSERT INTO CHILD (2, 'Paul')
INSERT INTO PARENT_CHILD (1, 1)
INSERT INTO PARENT_CHILD (1, 2)
INSERT INTO PARENT (2, 'Susan')
INSERT INTO CHILD (1, 'Oliver')  //Ooops ! duplicate insert
...


The last line violates the unique PK constraint in my db schema.

It seems that Hibernate does not keep track of what was already replicated in the same transaction.

Is this the expected behavior of cascading replicate ?
Is there another workaround that the one consisting in avoid using cascading replicate and replicate distinctly parents and then children ? (this would be a pain in our 'real-world' complex data model)


I'd love to hear about a nice'n'easy fix/workaround from the experts...


Thanks,

Gregory


PS :
Hibernate version: 3.0.5


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2008 7:50 am 
Newbie

Joined: Thu Jun 19, 2008 4:49 am
Posts: 12
two and a half years later i'm having the same problem.

hibernate tries to insert duplicated objects upon replicate.

any suggestions after two years?


Top
 Profile  
 
 Post subject: Re: Replication mode does not cascade
PostPosted: Wed Feb 22, 2017 7:41 am 
Beginner
Beginner

Joined: Tue Oct 20, 2009 6:28 am
Posts: 20
Fix it


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.