NHibernate version: 1.2.0 Beta3
NHibernateContrib version: 1.0.4.0
I've been using NHibernate Mapping Attributes for a while now to decorate my business objects and have started implementing relationships between objects. I have a Checklist object which has a collection of ChecklistItem objects. So in my Checklist object, I have:
Code:
[Property(9)]
public int DatasetID {...}
[Set(Name = "NHChecklistItems", Inverse = true, Lazy = false)]
[Key(Column = "ChecklistID")]
[OneToMany(Class = "PAO.BLL.ChecklistItem, PAO")]
private Iesi.Collections.ISet NHChecklistItems {...}
Sometimes when I run my testcases, they fail with the following error:
Code:
NHibernate.MappingException: (166,7): XML validation error: The element 'set' in namespace 'urn:nhibernate-mapping-2.2' has incomplete content. List of possible elements expected: 'urn:nhibernate-mapping-2.2:element urn:nhibernate-mapping-2.2:one-to-many urn:nhibernate-mapping-2.2:many-to-many urn:nhibernate-mapping-2.2:composite-element urn:nhibernate-mapping-2.2:many-to-any'. ---> System.Xml.Schema.XmlSchemaValidationException: The element 'set' in namespace 'urn:nhibernate-mapping-2.2' has incomplete content. List of possible elements expected: 'urn:nhibernate-mapping-2.2:element urn:nhibernate-mapping-2.2:one-to-many urn:nhibernate-mapping-2.2:many-to-many urn:nhibernate-mapping-2.2:composite-element urn:nhibernate-mapping-2.2:many-to-any'.
Then I look at the XML hibernate mapping generated by NHMA and notice that the key and one-to-many tags are missing from the set tag. At first this all seemed to happen at random, but in playing around with it, I noticed that I'd have a higher success rate if I moved the Set, Key, and OneToMany attributes (and their corresponding .NET property) up so that they weren't the last mapping attributes in the class. In other words, The likelyhood of an error occurring would be a lot less if I changed the order of the mappings to:
Code:
[Set(Name = "NHChecklistItems", Inverse = true, Lazy = false)]
[Key(Column = "ChecklistID")]
[OneToMany(Class = "PAO.BLL.ChecklistItem, PAO")]
private Iesi.Collections.ISet NHChecklistItems {...}
[Property(9)]
public int DatasetID {...}
Does the order of NHMA tags in the .NET code matter? All of the NHibernate examples I've seen show that any object's collection mappings come after that object's property mappings, so I also put my set mappings after the property mappings.
Hopefully I'm explaining this well enough. Thanks in advance.