NHibernate.MappingException:没有persister:XYZ
现在,在你说出来之前:我做了 Google,我的hbm.xml
文件是嵌入式资源。
这是我打电话的代码:
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: No persister for: HQData.Objects.SubCategory]NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(String entityName, Boolean throwIfNotFound) in c:CSharpNH2.0.0nhibernatesrcNHibernateImplSessionFactoryImpl.cs:766 NHibernate.Impl.SessionFactoryImpl.GetEntityPersister(String entityName) in c:CSharpNH2.0.0nhibernatesrcNHibernateImplSessionFactoryImpl.cs:752 NHibernate.Event.Default.DefaultLoadEventListener.OnLoad(LoadEvent event, LoadType loadType) in c:CSharpNH2.0.0nhibernatesrcNHibernateEventDefaultDefaultLoadEventListener.cs:37 NHibernate.Impl.SessionImpl.FireLoad(LoadEvent event, LoadType loadType) in c:CSharpNH2.0.0nhibernatesrcNHibernateImplSessionImpl.cs:2054 NHibernate.Impl.SessionImpl.Get(String entityName, Object id) in c:CSharpNH2.0.0nhibernatesrcNHibernateImplSessionImpl.cs:1029 NHibernate.Impl.SessionImpl.Get(Type entityClass, Object id) in c:CSharpNH2.0.0nhibernatesrcNHibernateImplSessionImpl.cs:1020 NHibernate.Impl.SessionImpl.Get(Object id) in c:CSharpNH2.0.0nhibernatesrcNHibernateImplSessionImpl.cs:985 HQData.DataAccessUtils.NHibernateObjectHelper.LoadDataObject(Int32 Id) in C:DevelopmentHQChannelRepoHQ Channel ApplicationHQChannelHQDataDataAccessUtilsNHibernateObjectHelper.cs:42 HQWebsite.LocalSearch.get_subCategory() in C:DevelopmentHQChannelRepoHQ Channel ApplicationHQChannelHQWebsiteLocalSearch.aspx.cs:17 HQWebsite.LocalSearch.Page_Load(Object sender, EventArgs e) in C:DevelopmentHQChannelRepoHQ Channel ApplicationHQChannelHQWebsiteLocalSearch.aspx.cs:27 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, 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
更新 ,这是我的方案的解决方案是什么:我已经改变了一些代码,我没有在运行时将配置文件添加到配置文件。
听起来像你忘了将映射程序集添加到会话工厂配置中。
如果你正在使用app.config ...
.
.
<property name="show_sql">true</property>
<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
<mapping assembly="Project.DomainModel"/> <!-- Here -->
</session-factory>
.
.
一些显而易见的东西,对于刚接触NHibernate的人来说非常有用。
应将所有XML映射文件视为嵌入式资源而不是默认内容。 该选项通过编辑文件属性中的Build Action属性进行设置。
然后将XML文件嵌入到程序集中,并在NHibernate配置阶段的项目启动时进行解析。
我的问题是我忘了将.hbm放在映射xml的名称中。 还要确保你使它成为一个嵌入式资源!
链接地址: http://www.djcxy.com/p/71047.html上一篇: NHibernate.MappingException: No persister for: XYZ
下一篇: How to clear the entire second level cache in NHibernate