为什么我用Nhibernate总是会报No persister for: Model.AdminInfo
我在webconfig里加了 <mapping assembly="Model" />
BulidAction 也改成Embedded Resource,还有哪里会错呢?
XML
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Model" namespace="Model" default-lazy="false">
<class name="AdminInfo" table="Admin">
<cache usage="read-write" />
<id name="AdminID" column="AdminID" type="Int32" unsaved-value="0">
<generator class="native" />
</id>
<property name="AdminName" type="String" length="32" not-null="false" />
<property name="AdminPassword" type="String" length="32" not-null="false" />
<property name="AdminStatus" type="Int32" not-null="false" />
<property name="AdminRole" type="Int32" not-null="false" />
<property name="AddTime" type="DateTime" length="50" not-null="false" />
</class>
</hibernate-mapping>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
<property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.connection_string">
Server=(local);initial catalog=Web;Integrated Security=SSPI
</property>
<mapping assembly="Model" />
</session-factory>
</hibernate-configuration>
.hbm.xml 设置为 嵌入的资源
Product.hbm.xml
对应数据库表的xml文件设置为潜入资源。
在属性窗口设置。
同问
同问。。对应数据库表的xml文件设置为潜入资源,这个已经设置了。还是不行。请问楼主解决了没有
是因为实体没有注册进来,在config.BuildSessionFactory()前面注册实体
如:config.AddAssembly("Model"); 把整个Model程序集加载进来
<mapping assembly="ShareClassPersistence"/>
<!--这个配置节点所保存的就是映射文件默认所在的程序集。这样当程序启动时,NHibernate就会自动去ShareClassPersistence寻找*.hbm.xml映射文件。如果NHibernate找不到映射文件,则可能会报如下错误:No persister for: xxx.xxx-->