I think I've found a bug in the processing of CompositeId attributes in NHMA. Specifically, it insists that KeyProperty items come before KeyManyToOne items. If a KeyManyToOne comes first, it will ignore all KeyProperty items that follow it!
I have a (fairly) simple object that has a composite key consisting of a many-to-one reference to a parent object, and an index (parent sees this as a list), in that order.
The nhibernate-mapping-2.2 xsd allows key-property and key-many-to-one elements can be mixed and matched in any order within composite-id. So I specified things like so:
[Class(...)]
public class Foo {
[CompositeId(1)]
[KeyManyToOne(2, Name="Parent", Column="bar_id")]
[KeyProperty(3, Name="Index", Column="foo_index")]
public Bar Parent {get;set;}
public int Index {get;set;}
}
The resultant mapping generated looks like so:
<hibernate-mapping ...>
<class ...>
<composite-id>
<key-many-to-one .../>
</composite-id>
</class>
</hibernate-mapping>
Note the missing key-property.
If I switch the order of the two Key attributes, I get both keys included. I checked the code for HbmWriter.WriteCompositeId, and this seems to be somewhat deliberate, is there a particular reason for it?
Hibernate version: NHibernate 1.2.0.GA
|