調試是出現這個錯誤:
MappingException: Unknown entity class: EDP.Provider.User
映射錯誤,未知的實體類User。
本以為是User的對應檔配置錯誤,但是確認User的對應檔User.hbm.xml沒有錯誤且已經將其嵌入工程,不是這兒的問題,那麼最有可能的就是 hibernate.cfg.xml 中的mapping有問題了,開啟一看,原來被屏蔽了:
我的hibernate.cfg.xml 檔案:
<?xml version='1.0' encoding='utf-8'?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.0">
<!-- ISessionFactory instance -->
<session-factory>
<!-- properties -->
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="show_sql">true</property>
<property name="dialect">NHibernate.JetDriver.JetDialect, NHibernate.JetDriver</property>
<property name="connection.driver_class">NHibernate.JetDriver.JetDriver, NHibernate.JetDriver</property>
<property name="connection.connection_string">Provider=Microsoft.Jet.OLEDB.4.0;Data Source=EDP.Website/AppData/BbsData.mdb;Persist Security Info=False</property>
<!--<mapping assembly="EDP.Provider" />-->
</session-factory>
</hibernate-configuration>
把 <mapping assembly="EDP.Provider" /> 行開啟就行了,意思是,映射 EDP.Provider 下的所有類,因為我把資料層和實體類放到一個dll工程 “EDP.Provider” 中了,所以只要指定映射EDP.Provider 下的所有類就OK 了。