-->
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: Delete a row from a table with 2 parents using replicate
PostPosted: Thu Jul 28, 2005 7:50 pm 
Newbie

Joined: Thu Jul 28, 2005 6:37 pm
Posts: 2
Friends,

This is the scenario. I have a table(CA) which has 2 parents(C and A). I am trying to move data from one database(D1) to another(D2) using replicate. Inserts and updates are working fine. However it is during delete that I am facing issues and requesting your help. If CA in D2 already has 2 records (c_id=1 and a_id=1 ; c_id=2 and a_id=2). If the present object from D1 has only one record(c_id=1 and a_id=1), I wanted the other record(c_id=2 and a_id=2) to be delete from CA in D2. But that is not happening.

Please see the mapping information and code snippet below for additional info.

Hibernate version:3.0.1

Mapping from Parent(C) :

<!-- bi-directional one-to-many association to CA -->
<set
name="cas"
lazy="false"
inverse="true"
cascade="all,delete-orphan"
>
<meta attribute="field-description">
@hibernate.set
lazy="false"
inverse="true"
cascade="all-delete-orphan"

@hibernate.collection-key
column="c_id"

@hibernate.collection-one-to-many
class="com.foo.xyz.beans.Ca"
</meta>
<key>
<column name="c_id" />
</key>
<one-to-many
class="com.foo.xyz.beans.Ca"
/>
</set>



This is the mapping from other parent(A)


<!-- bi-directional one-to-many association to CA -->
<set
name="cas"
lazy="false"
inverse="true"
cascade="none"
>
<meta attribute="field-description">
@hibernate.set
lazy="true"
inverse="true"
cascade="none"

@hibernate.collection-key
column="a_id"

@hibernate.collection-one-to-many
class="com.foo.xyz.beans.Ca"
</meta>
<key>
<column name="a_id" />
</key>
<one-to-many
class="com.foo.xyz.beans.Ca"
/>
</set>


Code Snippet:

List lst = D1.getList();

for (Iterator l_oIterator = lst.iterator(); lst.hasNext();) {
Obj obj = (Obj) lst.next();

Hibernate.initialize(obj);

D1Session.closeSession();

D2Connection.beginTransaction();
D2Connection.getSession().replicate(
obj, ReplicationMode.OVERWRITE);
D2Connection.commitTransaction();
}


Full stack trace of any exception that occurs: NO ERRORS or EXCEPTIONS

Name and version of the database you are using: Informix 9.3.0



Any help would be greatly appreciated. Thanks in advance.


Top
 Profile  
 
 Post subject: Delete row from a table with 2 parents using replicate()
PostPosted: Fri Jul 29, 2005 12:24 pm 
Newbie

Joined: Thu Jul 28, 2005 6:37 pm
Posts: 2
I was going thru the hibernate reference documentation to see if Im doing anything wrong and found this.

The ReplicationMode determines how replicate() will deal with conflicts with existing rows in the database.
• ReplicationMode.IGNORE - ignore the object when there is an existing database row with the same identifier
• ReplicationMode.OVERWRITE - overwrite any existing database row with the same identifier
• ReplicationMode.EXCEPTION - throw an exception if there is an existing database row with the same identifier
• ReplicationMode.LATEST_VERSION - overwrite the row if its version number is earlier than the version
number of the object, or ignore the object otherwise

It does not mention about deleting using replicate().

May I ask if this feature is available with replicate(). iF Yes, Could someone please help me with this.


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.