-->
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: Deleting a row from a table which has Collection of values
PostPosted: Thu Aug 11, 2005 12:29 pm 
Newbie

Joined: Fri Aug 05, 2005 4:32 am
Posts: 5
Hi,

I have class which is having collection of some other values which should go to different table. I am able to successfully insert values to both tables from the following mapping

<class name="Parent" table="Parent_table">
<id name="parentId" column="ID">
<generator class="increment" />
</id>
<property name="parentName" column="NAME" />
<set name="childValues" table="Child_table">
<key column="ID"/>
<element column="CHILD_ID" type="java.lang.String" not-null="true"/>
</set>
</class>

My tables are

Parent_table :
----------------
ID number (PK)
NAME varchar2(50)


Child_table:
--------------
ID number (FK references ID of Parent_table)
CHILD_ID varchar2(40) not null

Insertion and updation are working fine for me now. Now the problem is for the deletion of records from Child_table. As i don't have any mapping class for Child_table, i am unable to delete records from this table using HQL.

Now is it mandatory for me to create a class and have a mapping for it if i have to delete? or is there any other way i can do it without creating a class for this table?

_________________
With Regards,
Ravi


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 1:15 pm 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
You can delete child by removing them from the set of the parent children
Code:
session.open();
tx = session.beginTransaction();
parent = (Parent) session.get(...);
parent.getChildren().remove(myChild);
tx.commit();
session.close();

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


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.