本文介绍了使用NHibernate错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个例子的作为基础的例子。我创建的应用程序,但是当我执行此应用程序得到以下错误。

 没有配置ProxyFactoryFactory。

初​​始化proxyfactory.factory_class与现有的NHibernate.Byte code供应商之一的会话工厂配置部分的财产。
例:
NHibernate.Byte code.LinFu.ProxyFactoryFactory,NHibernate.Byte code.LinFu
例:
NHibernate.Byte code.Castle.ProxyFactoryFactory,NHibernate.Byte code.Castle

以下是code片段我使用。

 使用系统;
使用System.Collections.Generic;
使用System.Linq的;
使用的System.Web;
使用System.Web.UI程序;
使用System.Web.UI.WebControls;
使用NHibernate;
使用NHibernate.Cfg;公共部分类_Default:System.Web.UI.Page
{
    保护无效的Page_Load(对象发件人,EventArgs的发送)
    {
        配置CFG =新配置();
        cfg.AddAssembly(NHibernate的);
        ISessionFactory工厂= cfg.BuildSessionFactory(); //在该行得到错误
        ISession的会话= factory.OpenSession();
        ITransaction事务= session.BeginTransaction();
        用户NEWUSER =新用户();
        newUser.Id =joe_cool;
        newUser.UserName =约瑟夫·COOL;
        newUser.Password =ABC123
        newUser.EmailAddress [email protected];
        newUser.LastLogon = DateTime.Now;        //告诉NHibernate的,这个对象应该被保存
        session.Save(NEWUSER);        //提交所有的改变DB和关闭的Isession
        器transaction.commit();
        session.Close();    }
}


解决方案

也许你缺少你建立工厂部分前设置ProxyFactoryFactoryClass属性。

是这样的:

  Config.SetProperty(NHibernate.Cfg.Environment.ProxyFactoryFactoryClassNHibernate.Byte code.Linfu.ProxyProxyFactory,NHibernate.Byte code.Linfu);

不要忘了在项目中包含的李林甫DLL。

编辑:出现这种情况是由于更新引用城堡拆除。您可以在这里获得更多的信息:的

Considering this example as a base example. I created the application but when I execute this application getting the following error.

    The ProxyFactoryFactory was not configured.

Initialize 'proxyfactory.factory_class' property of the session-factory configuration section with one of the available NHibernate.ByteCode providers.Example:NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFuExample:NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle

Following is the code snippet i am using.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NHibernate;
using NHibernate.Cfg;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Configuration cfg = new Configuration();
        cfg.AddAssembly("NHibernate");


        ISessionFactory factory = cfg.BuildSessionFactory(); //getting error at this line
        ISession session = factory.OpenSession();
        ITransaction transaction = session.BeginTransaction();
        User newUser = new User();
        newUser.Id = "joe_cool";
        newUser.UserName = "Joseph Cool";
        newUser.Password = "abc123";
        newUser.EmailAddress = "[email protected]";
        newUser.LastLogon = DateTime.Now;

        // Tell NHibernate that this object should be saved
        session.Save(newUser);

        // commit all of the changes to the DB and close the ISession
        transaction.Commit();
        session.Close();

    }
}
解决方案

Maybe you are missing to set the ProxyFactoryFactoryClass property before building you section factory.

Something like:

Config.SetProperty(NHibernate.Cfg.Environment.ProxyFactoryFactoryClass, "NHibernate.ByteCode.Linfu.ProxyProxyFactory, NHibernate.Bytecode.Linfu");

Don't forget to include the Linfu dll in your project.

EDIT: this happens due to an update to reference to Castle removed. You may obtain more information here: http://nhforge.org/blogs/nhibernate/archive/2008/11/09/nh2-1-0-bytecode-providers.aspx

这篇关于使用NHibernate错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 02:57