c# - Many-to-One Mapping in NHibernate Not Working? -
i have following example persistent classes:
using nhibernate.mapping.attributes; namespace gumidal.domain { [class] public class foo { [id(0)] [generator(1, class="identity")] public virtual int id { get; set; } [property] public virtual string name { get; set; } } [class] public class bar { [id(0)] [generator(1, class = "identity")] public virtual int id { get; set; } [manytoone(name="foo")] public virtual foo foo { get; set; } } }
serializing assembly creates following xml:
<!-- generated nhibernate.mapping.attributes on 2015-10-02 13:08:49z. --> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"> <class name="example.domain.foo, exampleassembly"> <id> <generator class="identity"/> </id> <property name="name"/> </class> <class name="example.domain.bar, exampleassembly"> <id> <generator class="identity"/> </id> <many-to-one name="foo"/> </class> </hibernate-mapping>
but when try set configuration, exception following message , stack trace:
not compile deserialized mapping document. first chance exception of type 'nhibernate.mappingexception' occurred in nhibernate.dll @ nhibernate.cfg.configuration.logandthrow(exception exception) in c:\projects\nhibernate-core\src\nhibernate\cfg\configuration.cs:line 344 @ nhibernate.cfg.configuration.adddeserializedmapping(hbmmapping mappingdocument, string documentfilename) in c:\projects\nhibernate-core\src\nhibernate\cfg\configuration.cs:line 532 @ nhibernate.cfg.configuration.addvalidateddocument(namedxmldocument doc) in c:\projects\nhibernate-core\src\nhibernate\cfg\configuration.cs:line 501 @ nhibernate.cfg.configuration.processmappingsqueue() in c:\projects\nhibernate-core\src\nhibernate\cfg\configuration.cs:line 1867 @ nhibernate.cfg.configuration.adddocumentthroughqueue(namedxmldocument document) in c:\projects\nhibernate-core\src\nhibernate\cfg\configuration.cs:line 1858 @ nhibernate.cfg.configuration.addxmlreader(xmlreader hbmreader, string name) in c:\projects\nhibernate-core\src\nhibernate\cfg\configuration.cs:line 1851 @ nhibernate.cfg.configuration.addinputstream(stream xmlinputstream, string name) in c:\projects\nhibernate-core\src\nhibernate\cfg\configuration.cs:line 640 @ nhibernate.cfg.configuration.addinputstream(stream xmlinputstream) in c:\projects\nhibernate-core\src\nhibernate\cfg\configuration.cs:line 614 @ example.domain.tests.setup()
everything looks correct in xml me... ideas i'm missing?
the name=""
attribute represents c# property. so, should use
// instead of <many-to-one name="foo_id"/> // need <many-to-one name="foo" column="foo_id"/>
so, name of property foo
not foo_id. guess need mapping this:
//[manytoone(name="foo_id")] [manytoone(column="foo_id")] public virtual foo foo { get; set; }
with full stack exception easier, also, <id>
element should have name:
<id name="id" column="foo_id"...
Comments
Post a Comment