-->
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: how to delete database up to 3 or more relationship tables
PostPosted: Wed Feb 15, 2006 2:55 am 
Newbie

Joined: Wed Feb 08, 2006 4:10 am
Posts: 16
Here is the Mapping file:

these 3 tables relationships as:
Customer->Address->contact
Customer.hbm.xml:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Customer.Customer, Customer" table="Customer">
<id name="Cust_ID" column="ID" type="Int32">
<generator class="identity"></generator>
</id>
<property name="Cust_UID" column="UID" type="Guid" />
<property name="Cust_Name" column="Name" type="String(50)" />
<property name="Cust_RegNo" column="RegNo" type="String(20)" />
<property name="Cust_Website" column="Website" type="String(67)" />
<set name="Cust_ContactPerson" inverse="true" table="Address" cascade="all-delete-orphan">
<key column="ID" />
<one-to-many class="Customer.Address, Customer" />
</set>
</class>
</hibernate-mapping>

Address.hbm.xml:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Customer.Address, Customer" table="Address">
<id name="Add_ID" column="ID" type="Int32">
<generator class="identity"></generator>
</id>
<property name="Add_UID" column="UID" type="Guid" />
<property name="Add_Name" column="Name" type="String(50)" />
<property name="Add_Language" column="Language" type="String(50)" />
<property name="Add_Postal" column="Postal" type="String(320)" />
<property name="Add_Address1" column="Address1" type="String(50)" />
<property name="Add_Address2" column="Address2" type="String(50)" />
<property name="Add_Address3" column="Address3" type="String(50)" />
<property name="Add_City" column="City" type="String(50)" />
<property name="Add_Postcode" column="Postcode" type="String(20)" />
<property name="Add_State" column="State" type="String(50)" />
<property name="Add_Country" column="Country" type="String(20)" />
<property name="Add_CustID" column="CustID" type="Int32" />
<set name="Add_Contacts" inverse="true" table="Contact" cascade="all-delete-orphan">
<key column="ID"/>
<one-to-many class="Customer.Contact, Customer" />
</set>
<many-to-one name="Add_Customers" column="CustID" insert="false" update="false" cascade="all" />
</class>
</hibernate-mapping>

Contact.hbm.xml:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="Customer.Contact, Customer" table="Contact">
<id name="Con_ID" column="ID" type="Int32">
<generator class="identity" />
</id>
<property name="Con_UID" column="UID" type="Guid" />
<property name="Con_Type" column="Type" type="Int32" />
<property name="Con_Contents" column="Contents" type="String(255)" />
<property name="Con_AddressID" column="AddressID" type="Int32" />
<many-to-one name="Con_Addresss" column="AddressID" insert="false" update="false" cascade="all" />
</class>
</hibernate-mapping>

When i testing using this code:
Dim custs As Customer.Customer = session.Load(GetType(Customer.Customer), 2)

session.Delete(custs)

session.Flush()

session.Close()


The Error: "The DELETE statement conflicted with the REFERENCE constraint "FK_Contact_Address". The conflict occurred in database "

Pls help...thanks


Top
 Profile  
 
 Post subject: Re: how to delete database up to 3 or more relationship tabl
PostPosted: Fri Feb 17, 2006 8:30 am 
Beginner
Beginner

Joined: Fri Nov 11, 2005 1:04 pm
Posts: 22
You need to use the Cascade property to tell NHibernate that you want to delete the child relations when the parent object is deleted.

The other alternative is to set the table to cascade on delete within your DBMS.


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.