Archive for February, 2008
NHibernate composite-element mapping
Friday, February 15th, 2008A tip for mapping value objects that is sort of buried in the NHibernate documentation.
Please note that a composite element mapping doesn't support null-able properties if you're using a <set>. NHibernate has to use each columns value to identify a record when deleting objects (there is no separate primary key column in the composite element table), which is not possible with null values.
When you fail to follow this guidance you get orphaned records left in the database when you delete them from the collection. When I fail to read the documentation (again) I learn a good lesson about how important it is to read the documentation (again). =)
After properly implementing Equals() and GetHashCode() with cascade="all" the persistence (and deletion) is transparent.
Just set 'em all to not-null.
Here is an example mapping from CodeCampServer:
<set name="Sponsors" table="Sponsors" cascade="all"> <key column="ConferenceId" /> <composite-element class="Sponsor"> <property name="Level" not-null="true"/> <property name="Name" length="50" not-null="true"/> <property name="LogoUrl" length="260" not-null="true"/> <property name="Website" length="260" not-null="true"/> <nested-composite-element name="Contact" class="Contact"> <property name="FirstName" length="20" not-null="true"/> <property name="LastName" length="20" not-null="true"/> <property name="Email" length="60" not-null="true"/> </nested-composite-element> </composite-element> </set>
Blogging at FWDNUG
Friday, February 15th, 2008I've been posting to a blog on fwdnug.com.
4 Links Today (2008-02-14)
Thursday, February 14th, 20082 Links Today (2008-02-13)
Wednesday, February 13th, 20084 Links Today (2008-02-11)
Monday, February 11th, 20084 Links Today (2008-02-09)
Saturday, February 9th, 20084 Links Today (2008-02-08)
Friday, February 8th, 2008-
A port of the ActiveSupport library from Ruby to C# 3.0.
9 Links Today (2008-02-07)
Thursday, February 7th, 2008-
pdf link on page
-
golden comments
9 Links Today (2008-02-06)
Wednesday, February 6th, 2008-
How do you decide what to make next?
-
utility to download all the .net source