You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by Vani <va...@tcs.com> on 2006/08/24 16:13:21 UTC

Deleting a row in the childtable

Hi all,

I have a parent table eg Department(DeptID,DeptName) and a childtable eg
Employee(EmpId, EmpName,DeptID). Now my problem is, I want to delete a row
in the child table if its corresponding foreign key(Dept ID) is deleted in
the parent table. How do i implement it using Ibatis?

Please help me.

Thank you.
-- 
View this message in context: http://www.nabble.com/Deleting-a-row-in-the-childtable-tf2158879.html#a5964724
Sent from the iBATIS - User - Cs forum at Nabble.com.


Re: Deleting a row in the childtable

Posted by Larry Meadors <lm...@apache.org>.
The simple answer is "You don't - there is not an 'iBATIS way' to do this."

You can however do a couple of things.

In your database, you can define cascading deletes, so that when you
delete a parent, you delete the children, too.

You can also (on some databases) execute multiple statements in one
mapped statement. For example using Oracle, you could do this:

<delete id="delete">
 BEGIN
  DELETE FROM Child WHERE parentId=#parentId#;
  DELETE FROM Parent WHERE parentId=#parentId#;
 END;
</delete>

Larry

PS: I just noticed that this is the CS list, not the java list - that
mapped statement is from an example I had using the Java syntax, which
iirc, is the same, but if not...sorry. ;-)


On 8/24/06, Vani <va...@tcs.com> wrote:
>
> Hi all,
>
> I have a parent table eg Department(DeptID,DeptName) and a childtable eg
> Employee(EmpId, EmpName,DeptID). Now my problem is, I want to delete a row
> in the child table if its corresponding foreign key(Dept ID) is deleted in
> the parent table. How do i implement it using Ibatis?
>
> Please help me.
>
> Thank you.
> --
> View this message in context: http://www.nabble.com/Deleting-a-row-in-the-childtable-tf2158879.html#a5964724
> Sent from the iBATIS - User - Cs forum at Nabble.com.
>
>