-->
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: Cascade Update
PostPosted: Tue Nov 15, 2005 3:14 am 
Hi,
i am a new user of NHibernate.
I have a problem with Cascade Update on 1-Many relations.
How do i implement it? I have 2 tables:
Customers:
CustomerID-nchar(5)-Primary Key,
CompanyName-nvarchar(40),
ContactName-nvarchar(30)-Unique Key,
Address-nvarchar(60)
City-nvarchar(15)
Region-nvarchar(15)
PostalCode-nvarchar(10)

Orders
OrderID-GUID-PrimaryKEy
CustomerID-Foreign Key ref Customers(CustomerID)
OrderDate
ShippedDate
ShipAddress
SHipCity
ShipRegion
ShipPostalCode
CustName-ref Customers(ContactName)

If i update the Parent table Customers i need the child table also to be updated i.e if i update the ContactName in Customers table then i need the CustName in Orders table also be updated for the respective CustomerID.
Please let me know how do i do it?
Here is my Customers.hbm.xml file

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="nhibernator.BLL.Customer, nhibernator" table="Customers">
<!-- map the id field -->
<composite-id>
<key-property name="CustomerID" column="CustomerID" type="String" length="20">
<generator class="assigned" />
</key-property>
<key-property name="ContactName" column="ContactName" type="String">
<generator class="assigned" />
</key-property>
</composite-id>
<!-- Map properties I'd like to persist/fetch, assume column = propery name, and type is determined by reflection -->
<property name="CompanyName"/>
<property name="Address"/>
<property name="City"/>
<property name="Region"/>
<property name="PostalCode"/>
<!-- Orders collection, pull customer orders but, loading lazy to minimize load time, resource usage. -->
<!--<set name="Details" cascade="all" table="CustomerDetails" lazy="true">
<key column="CustomerID"/>
<one-to-many class="nhibernator.BLL.Details, nhibernator"/>
</set>-->
<bag name="Orders" cascade="all" lazy="true">
<key column="CustomerID"/>
<one-to-many class="nhibernator.BLL.Order, nhibernator"/>
</bag>
</class>
</hibernate-mapping>


Here is my Orders.hbm.xml file
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="nhibernator.BLL.Order, nhibernator" table="Orders">
<id name="OrderID" type="Int32" unsaved-value="0">
<generator class="identity" />
</id>
<property name="CustomerID" length="20"/>
<property name="OrderDate" type="DateTime"/>
<property name="ShippedDate" type="DateTime"/>
<property name="ShipName"/>
<property name="ShipAddress"/>
<property name="ShipCity"/>
<property name="ShipRegion"/>
<property name="ShipPostalCode"/>
<set name="Products" table="[Order Details]">
<key column="OrderID"/>
<many-to-many class="nhibernator.BLL.Product, nhibernator" column="ProductID"/>
</set>
<!--<many-to-one name="OCustomer" class="nhibernator.BLL.Customer,nhibernator" column="CustomerID"/>-->
</class>
</hibernate-mapping>


Please let me know what changes should i make to make it work.
Quote:
[code][/code]


Top
  
 
 Post subject:
PostPosted: Thu Nov 17, 2005 11:26 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Can you post the code you are executing? And tell us how you know that it doesn't work?

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


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.