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>