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: Delete cascade objects
PostPosted: Mon Aug 14, 2006 10:28 am 
Newbie

Joined: Mon Aug 14, 2006 9:50 am
Posts: 2
Hello, everybody!
I have got the following problem.
I have Parent and Child classes.

// Parent class

namespace ParentChild
{
public class Parent
{
public int Id
{ get{ return _id;}
set{ _id = value;}
}
private int _id = -1;

public IList Children
{
get{ return _children;}
set{ _children = value;}
}
private IList _children = new ArrayList();

public Parent(){}
}
}

// Child class

// Parent class

namespace ParentChild
{
public class Child
{
public int Id
{ get{ return _id;}
set{ _id = value;}
}
private int _id = -1;

public Parent ParentInstance
{
get{ return _parentInstance;}
set{ _parentInstance = value;}
}
private Parent _parentInstance;
public Child(){}
}
}

and here is the mapping file:

<class name="ParentChild.Parent, ParentChild" table="Parents">
<id name="Id" column="Id" type="Int32" length="4" unsaved-value="-1">
<generator class="identity" />
</id>
<bag name="Children" lazy="true" inverse="true" cascade="all">
<key column="Id" />
<one-to-many class="ParentChild.Child, ParentChild"/>
</bag>
</class>

<class name="ParentChild.Child, ParentChild" table="Children">
<id name="Id" column="Id" type="Int32" length="4" unsaved-value="-1">
<generator class="identity" />
</id>
<many-to-one class="ParentChild.Parent, ParentChild" column="ParentId"/>
</class>


I want to delete parent object and all its children.But I have the following exception message: "DELETE statement conflicted with COLUMN REFERENCE". I know it's not a hard problem, but I haven't solved it yet :(.


Top
 Profile  
 
 Post subject: Re: Delete cascade objects
PostPosted: Tue Aug 15, 2006 8:19 am 
Beginner
Beginner

Joined: Wed Apr 19, 2006 9:16 am
Posts: 24
Your mapping:
Code:
<class name="ParentChild.Parent, ParentChild" table="Parents">
  <id name="Id" column="Id" type="Int32" length="4" unsaved-value="-1">
    <generator class="identity" />
  </id>
  <bag name="Children" lazy="true" inverse="true" cascade="all">
       <key column="Id" />
       <one-to-many class="ParentChild.Child, ParentChild"/>
  </bag>
</class>

<class name="ParentChild.Child, ParentChild" table="Children">
  <id name="Id" column="Id" type="Int32" length="4" unsaved-value="-1">
    <generator class="identity" />
  </id>
  <many-to-one class="ParentChild.Parent, ParentChild" column="ParentId"/>
</class>


I think the "key" element of the bag should be mapped as

Code:
<key column="ParentId">

_________________
regards,
Willem van Rumpt


Top
 Profile  
 
 Post subject: Solved
PostPosted: Fri Aug 18, 2006 6:40 am 
Newbie

Joined: Mon Aug 14, 2006 9:50 am
Posts: 2
I found the solution of the problem.It was in database structure.There were old relations between my tables.The problem was solved after deleting those relations


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.