Hey guys,
I'm trying to understand cascades a little bit, and I seem to have run into a snag of sorts. I'm using NHibernate 1.0.0.
This is a sample hbm file for what I'm trying to do:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="BiaCreations.Core.Planet, BiaCreations.Core" table="Planets">
<cache usage="read-write" />
<id name="Id" column="PlanetId" type="Int32" unsaved-value="-1">
<generator class="native">
<param name="sequence">pm_planet_planetid_seq</param>
</generator>
</id>
<property name="Name" column="Name" type="string" length="64" />
<bag name="People" inverse="true" cascade="delete" lazy="true">
<cache usage="read-write" />
<key column="PlanetId" />
<one-to-many class="BiaCreations.Core.Person, BiaCreations.Core" />
</bag>
</class>
<class name="BiaCreations.Core.Person, BiaCreations.Core" table="People">
<cache usage="read-write" />
<id name="Id" column="PersonId" type="Int32" unsaved-value="-1">
<generator class="native">
<param name="sequence">pm_person_personid_seq</param>
</generator>
</id>
<property name="Name" column="Name" type="string" length="64" />
<many-to-one cascade="save-update"
name="Planet"
class="BiaCreations.Core.Planet, BiaCreations.Core"
column="PlanetId"
not-null="true"
/>
<bag name="Items" inverse="true" cascade="delete" lazy="true">
<cache usage="read-write" />
<key column="PersonId" />
<one-to-many class="BiaCreations.Core.Item, BiaCreations.Core" />
</bag>
</class>
<class name="BiaCreations.Core.Item, BiaCreations.Core" table="Items">
<cache usage="read-write" />
<id name="Id" column="ItemId" type="Int32" unsaved-value="-1">
<generator class="native">
<param name="sequence">pm_item_itemid_seq</param>
</generator>
</id>
<property name="Name" column="Name" type="string" length="64" />
<many-to-one cascade="save-update"
name="Person"
class="BiaCreations.Core.Person, BiaCreations.Core"
column="PersonId"
not-null="true"
/>
</class>
</hibernate-mapping>
__________________
Now in code, say I have a Planet object that has a couple Person objects in it's People collection. If I create a new Item, I would think that both the Person object and Planet object would be updated because of the cascade options that I specified.
That doesn't seem to be the case, though. I'm seeing the Person object being updated, but the Planet object doesn't seem to be. It contains an old version of the Person object in the People collection.
Am I doing something wrong or is this a limitation with cascading?
If you need more info, please let me know.
Thanks
Jim
_________________ Jim Geurts
CEO/Founder, Bia Creations
http://biacreations.com
Office: 414.213.1903
Fax: 414.294.3702
|