2011-04-12 61 views
0

我正在設置我的第一個nHibernate項目。我創建了一個接受名稱和ID的簡單Web表單,但是我一直收到以下錯誤:nHibernate ProxyFactory問題

ProxyFactoryFactory未配置。 使用其中一個可用的NHibernate.ByteCode提供程序初始化會話工廠配置部分的'proxyfactory.factory_class'屬性。 例子: NHibernate.ByteCode.LinFu.ProxyFactoryFactory,NHibernate.ByteCode.LinFu 例子: NHibernate.ByteCode.Castle.ProxyFactoryFactory,NHibernate.ByteCode.Castle

我已經添加到兩個城堡和李林甫的引用我的項目。我也配置了web.config中的以下內容:

<section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" allowDefinition="Everywhere"/> 

你能告訴我是怎麼回事?我已經嘗試了一切。是從VisualNHibernate導入了很多我的映射等嗎?感謝幫助。

回答

0

你必須指定你打算什麼代理工廠使用,例如:

<property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>` 

,此外,您發佈的配置OS06包含...什麼都沒有,請確保有一個適當的最低配置沒有它你不能創建NH會話工廠。

+0

對不起,這裏是配置: <添加鍵= 「hibernate.connection.provider」 值= 「NHibernate.Connection.DriverConnectionProvider」/> <添加鍵= 「hibernate.dialect」 值=「NHibernate的.Dialect.MsSql2005Dialect「/> James 2011-04-12 16:16:48

+0

@ric,所以添加我在回覆中建議的代碼(用於您想要的代理)大會需要,它會工作 – 2011-04-12 16:24:31

+0

感謝您的幫助,我試過但仍然得到相同的錯誤 – James 2011-04-12 16:31:42

0

您需要添加適當的ProxyFactoryFactory,並讓NHibernate知道應該使用什麼實現來創建代理對象。 Fabio在前段時間發佈瞭如何在nhibernate.info上完成:http://nhibernate.info/blog/2008/11/09/nh2-1-0-bytecode-providers.html 我也強烈建議閱讀documentation about configuration of NHibernate

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" > 
    <session-factory name="YourAppName"> 
     <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property> 
     <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> 
     <property name="connection.connection_string"> 
      Server=(local);initial catalog=nhibernate;Integrated Security=SSPI 
     </property> 
     <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property> 
    </session-factory> 
</hibernate-configuration> 
+0

對不起,我忘了發佈整個配置: – James 2011-04-12 16:16:17