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
|