-->
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: bug with h3 tools OR is there a mistake with my model?
PostPosted: Tue Feb 15, 2005 9:46 am 
Beginner
Beginner

Joined: Thu Feb 03, 2005 7:23 pm
Posts: 23
Hello,

I have a parent and child object. The child object has a:

<many-to-one name="source" class="Node" column="SOURCE" cascade="delete" not-null="true"/>

statement referring to the parent object. The parent object does NOT have a
collection mapping that keeps the child objects, or anything like that.

When I run schema export with H3 tools, the table holding the child objects is NOT created with on-delete cascade. But it has foreign keys referring to the parent object. So when I try to delete the parent, I get a constraint violated error. If I open the DB (Oracle 10g) with PL/SQL developer, and change the child table columns with the FK to cascade on delete, everything works ok.
(e.g. when I delete the parent object, the referring child objects also gets deleted, (by foreign key).

Is there a terrible mistake with my model? (like I should have a set in parent object that keeps the child objects) OR is it just a bug in H3 tools not creating the table with cascade on-delete statements? It could just be when I manually set the cascade option, things work -but on coincidence.

From: http://www.hibernate.org/200.html it says:
Hibernate3 will allow the use ON DELETE CASCADE foreign key definitions when this is supported by the underlying database.

So, I am not really sure if this is just a simple error with my mappings, or if H3 tools just did not create cascade correctly with oracle, or if there is a horrible mistake with my model and I am messing with internal workings of hibernate by manually changing things on the schema.

Please help.

Best Regards,
-O.B.

Here is paste of my classses and my mapping files:

parent object:
----------------

public class VertexNode implements Serializable {

private long vid;

public VertexNode () {
}

public long getVid () {
return this.vid;
}

public void setVid (long vid) {
this.vid = vid;
}


}

child object:
--------------

public class EdgeNode implements Serializable {

private long eid;
private VertexNode source;
private VertexNode target;

public EdgeNode () {
}

public long getEid () {
return this.eid;
}
public void setEid (long eid) {
this.eid = eid;
}

public VertexNode getSource () {
return this.source;
}

public void setSource (VertexNode source) {
this.source = source;
}

public VertexNode getTarget () {
return this.target;
}

public void setTarget (VertexNode target) {
this.target = target;
}

}

parent mapping:
-------------------
<hibernate-mapping>

<class name="Node" table="VERTEX">
<id name="vid" type="long">
<generator class="sequence" />
</id>
</class>

</hibernate-mapping>

child mapping:
-----------------
<hibernate-mapping>

<class name="EdgeNode" table="EDGE">
<id name="eid" type="long">
<generator class="sequence" />
</id>
<many-to-one name="source" class="VertexNode" column="SOURCE" cascade="delete" not-null="true"/>
<many-to-one name="target" class="VertexNode" column="TARGET" cascade="delete" not-null="true"/>
</class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 15, 2005 9:52 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
cascade="delete" does not imply this.


<key on-delete="cascade"/> does, as per the user guide.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 15, 2005 10:15 am 
Beginner
Beginner

Joined: Thu Feb 03, 2005 7:23 pm
Posts: 23
gavin wrote:
cascade="delete" does not imply this.


<key on-delete="cascade"/> does, as per the user guide.


Hello,

where should I stick in <key on-delete="cascade"/> in my mapping?

OR

are you saying that my parent class should have a set, and the key should be in that set mapping?

I am trying to avoid the set in my parent class as much as possible.

Thank you very much.


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.