现在,在您说出来之前:我做了 Google,我的hbm.xml
文件是 Embedded Resource。
这是我正在调用的代码:
ISession session = GetCurrentSession();
var returnObject = session.Get<T>(Id);
这是我的班级映射文件:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="HQData.Objects.SubCategory, HQData" table="SubCategory" lazy="true">
<id name="ID" column="ID" unsaved-value="0">
<generator class="identity" />
</id>
<property name="Name" column="Name" />
<property name="NumberOfBuckets" column="NumberOfBuckets" />
<property name="SearchCriteriaOne" column="SearchCriteriaOne" />
<bag name="_Businesses" cascade="all">
<key column="SubCategoryId"/>
<one-to-many
class="HQData.Objects.Business, HQData"/>
</bag>
<bag name="_Buckets" cascade="all">
<key column="SubCategoryId"/>
<one-to-many
class="HQData.Objects.Bucket, HQData"/>
</bag>
</class>
</hibernate-mapping>
有人遇到过这个问题吗?
这是完整的错误消息:
MappingException:对于以下对象没有持久性:HQData.Objects.SubCategory] NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(String entityName,Boolean throwIfNotFound) 在c:\ CSharp \ NH2.0.0 \ nhibernate \ src \ NHibernate \ Impl \ SessionFactoryImpl.cs:766 NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(String entityName) 在c:\ CSharp \ NH2.0.0 \ nhibernate \ src \ NHibernate \ Impl \ SessionFactoryImpl.cs:752 NHibernate.Event.Default.DefaultLoadEventListener.OnLoad(LoadEvent事件,LoadType loadType) 在c:\ CSharp \ NH2.0.0 \ nhibernate \ src \ NHibernate \ Event \ Default \ DefaultLoadEventListener.cs:37 NHibernate.Impl.SessionImpl.FireLoad(LoadEvent event,LoadType loadType) 在c:\ CSharp \ NH2.0.0 \ nhibernate \ src \ NHibernate \ Impl \ SessionImpl.cs:2054 NHibernate.Impl.SessionImpl.Get(字符串entityName,Object id) 在c:\ CSharp \ NH2.0.0 \ nhibernate \ src \ NHibernate \ Impl \ SessionImpl.cs:1029 NHibernate.Impl.SessionImpl.Get(TypeEntityClass,Object id) 在c:\ CSharp \ NH2.0.0 \ nhibernate \ src \ NHibernate \ Impl \ SessionImpl.cs:1020 NHibernate.Impl.SessionImpl.Get(对象ID) 在c:\ CSharp \ NH2.0.0 \ nhibernate \ src \ NHibernate \ Impl \ SessionImpl.cs:985 HQData.DataAccessUtils.NHibernateObjectHelper.LoadDataObject(Int32 Id) 在C:\ Development \ HQChannelRepo \ HQ Channel Application \ HQChannel \ HQData \ DataAccessUtils \ NHibernateObjectHelper.cs:42中HQWebsite.LocalSearch.get_subCategory() 在C:\ Development \ HQChannelRepo \ HQ Channel Application \ HQChannel \ HQWebsite \ LocalSearch.aspx.cs:17 HQWebsite.LocalSearch.Page_Load(Object sender,EventArgs e) 在C:\ Development \ HQChannelRepo \ HQ Channel Application \ HQChannel \ HQWebsite \ LocalSearch.aspx.cs:27 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,Object o,Object t,EventArgs e)+15 System.Web .Util.CalliEventHandlerDelegateProxy.Callback(对象发送者,EventArgs e)+33 System.Web.UI.Control.OnLoad(EventArgs e)+99 System.Web.UI.Control.LoadRecursive()+47 System.Web.UI.Page .ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)+1436
更新,这里就是为解决我的情况是:我已经改变了一些代码,我在运行时没有加入大会的配置文件。