我建有2个表:Parents表(parent_id int(自增型),Name varchar(50))
Childs表 (child_id int(自增型),Address varchar(50),parent_id int(与Parents表中的parent_id列相对应) )以下是父类Parent.hbn.xml的代码<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="wangzheWebNhihernate.Parent,wangzheWebNhihernate" table="Parents">
<id type="Int32" name="ParentId" column="parent_id" unsaved-value="0">
<generator class="identity" />
</id>
<property type="String" name="Name" column="Name" length="50"/>
<set name="Childs" cascade="all" inverse="true" lazy="false"
table="Childs"sort="unsorted">
<key column="parent_id" />
<one-to-many class="wangzheWebNhihernate.Child,wangzheWebNhihernate"/>
</set>
</class>
</hibernate-mapping>以下的是子类的Child.hbm.xml代码<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="wangzheWebNhihernate.Child,wangzheWebNhihernate" table="Childs" dynamic-update="false" dynamic-insert="false">
<id type="Int32" column="child_id" unsaved-value="0" name="ChildId">
<generator class="identity" />
</id>
<property name="Address" column="Address" type="String" length="50"/>
<many-to-one
name="PParent"
column="parent_id"
class="wangzheWebNhihernate.Parent,wangzheWebNhihernate"
cascade="none"
outer-join="true"
update="true"
insert="true"
access="property"
/>
</class>
</hibernate-mapping>
可是在运行configuration.AddXmlFile()这个方法时应该加载哪个文件呀(现在有Parent.hbm.xml和Child.hbm.xml这两个文件),后来我加载了Parent.hbm.xml文件
( configuration.AddXmlFile(Server.MapPath("Parent.hbm.xml"));),但运行到(ISessionFactory iSessionFactory = configuration.BuildSessionFactory();)报的错误是:An association from the table Childs refers to an unmapped class: Parent.后来我又加载了Child.hbm.xml这个文件( configuration.AddXmlFile(Server.MapPath("Parent.hbm.xml"));),但运行到(ISessionFactory iSessionFactory = configuration.BuildSessionFactory();)报的错误是Association references unmapped class: Child.请问知道是为什么吗?
Childs表 (child_id int(自增型),Address varchar(50),parent_id int(与Parents表中的parent_id列相对应) )以下是父类Parent.hbn.xml的代码<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="wangzheWebNhihernate.Parent,wangzheWebNhihernate" table="Parents">
<id type="Int32" name="ParentId" column="parent_id" unsaved-value="0">
<generator class="identity" />
</id>
<property type="String" name="Name" column="Name" length="50"/>
<set name="Childs" cascade="all" inverse="true" lazy="false"
table="Childs"sort="unsorted">
<key column="parent_id" />
<one-to-many class="wangzheWebNhihernate.Child,wangzheWebNhihernate"/>
</set>
</class>
</hibernate-mapping>以下的是子类的Child.hbm.xml代码<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="wangzheWebNhihernate.Child,wangzheWebNhihernate" table="Childs" dynamic-update="false" dynamic-insert="false">
<id type="Int32" column="child_id" unsaved-value="0" name="ChildId">
<generator class="identity" />
</id>
<property name="Address" column="Address" type="String" length="50"/>
<many-to-one
name="PParent"
column="parent_id"
class="wangzheWebNhihernate.Parent,wangzheWebNhihernate"
cascade="none"
outer-join="true"
update="true"
insert="true"
access="property"
/>
</class>
</hibernate-mapping>
可是在运行configuration.AddXmlFile()这个方法时应该加载哪个文件呀(现在有Parent.hbm.xml和Child.hbm.xml这两个文件),后来我加载了Parent.hbm.xml文件
( configuration.AddXmlFile(Server.MapPath("Parent.hbm.xml"));),但运行到(ISessionFactory iSessionFactory = configuration.BuildSessionFactory();)报的错误是:An association from the table Childs refers to an unmapped class: Parent.后来我又加载了Child.hbm.xml这个文件( configuration.AddXmlFile(Server.MapPath("Parent.hbm.xml"));),但运行到(ISessionFactory iSessionFactory = configuration.BuildSessionFactory();)报的错误是Association references unmapped class: Child.请问知道是为什么吗?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货