【问题标题】:NHibernate proxyexceptionNHibernate 代理异常
【发布时间】:2009-06-05 14:47:29
【问题描述】:

我是新的 NHibernate。我正在编写一个简单的应用程序,它的客户类包含 id 和 name,并使用 nhibernate 我将对象存储到数据库。 但我得到以下内容

未配置 ProxyFactoryFactory。 使用可用的 NHibernate.ByteCode 提供程序之一初始化会话工厂配置部分的“proxyfactory.factory_class”属性。 示例:<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>

阅读此错误后,我在我的应用程序中添加了参考 NHibernate.ByteCode.Castle。我仍然收到错误。我在 cfg.xml 文件中声明

hibernate.cfg.xml 文件

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="connection.connection_string">Server=(local);Initial Catalog=Customer;User Id=sa;Password=myPassword1</property>

  </session-factory>
</hibernate-configuration>

客户.hbm.xml

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="ConsoleApplication1" assembly="ConsoleApplication1">
  <class name="ConsoleApplication1.Customer" table="Customer">
    <id name="Id" type="string" length="40">
      <generator class="assigned"></generator>

    </id>
    <property name="Name" column="Name" type="String" length="40"></property>

  </class>

</hibernate-mapping>

主要功能

Configuration cfg = new Configuration();
cfg.AddAssembly(Assembly.GetCallingAssembly());

ISessionFactory factoty = cfg.BuildSessionFactory();
ISession session = factoty.OpenSession();
ITransaction TRANS = session.BeginTransaction();

Customer newCustomer = new Customer();
newCustomer.ID = "1";
newCustomer.Name = "test";

session.Save(newCustomer);
session.Close();

谁能帮助我? 提前致谢

【问题讨论】:

  • 您还需要对 Castle.Core.dll 和 Castle.DynamicProxy2.dll 的引用
  • 我添加了两个 dll 但仍然出现同样的错误。

标签: nhibernate


【解决方案1】:

同样的问题,同样的解决方法尝试。所有引用的 DLL 都设置为复制本地并在项目中。我正在使用带有 Castle 作为代理工厂的 hibernate.cfg.xml 文件。

奇怪的是,这只发生在我使用 SessionFactory 创建会话时。如果我切换到我通过 FluentNHibernate.SessionSource (PersistenceModel) 实例化会话的其他测试类,我不会收到此错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-03
    • 2011-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多