Friday, December 1, 2006

NHibernate 1.2 : not-found = ignore (many-to-one)

This is another excellent feature of NHibernate 1.2 that helps a lot to get legacy databases (90% of the world..? ;) ) working smoothly..

Why? Because in previous version orphaned records where always treated as an exception instead of having a more "soft" handling (Example: treat the object reference null).

If you are working with composite keys this scenario was even worse : valid null values (which should not be really be considered orphans) also raised an exception when 1 of it;s components is not null...

So, inside the Templates what we are doing is set that new XML property to "true" WHEN the relation is based on a composite key (please remmember you can always change the calculated value to whatever you like!).

NOTE: The only important thing to notice is that this will do an extra separate query (don't ask ME why, have no clue why that's needed.. )