问题描述
我是新来的NHibernate.我正在编写具有cusstomer类包含id和name的简单应用程序,并使用nhibernate将对象存储到数据库中.但我得到以下内容
I am new NHibernate.I am writing the simple application that have cusstomer class contains id and name and using nhibernate i am storing the object to database.but i am getting the following
未配置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>
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: <property name='proxyfactory.factory_class'>NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
Example: <property name='proxyfactory.factory_class'>NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
读取此错误后,我向应用程序中添加了参考NHibernate.ByteCode.Castle.仍然出现错误.并且我在cfg.xml文件中声明了
after reading this error i added reference NHibernate.ByteCode.Castle to my application.still i am getting the error .and i declared in cfg.xml file
hibernate.cfg.xml文件
hibernate.cfg.xml file
<?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>
customer.hbm.xml
customer.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();
有人可以帮助我吗?预先感谢
can anyone help me?thanks in advance
推荐答案
相同问题,尝试相同的解决方法.所有引用的DLL都设置为本地复制,并且位于项目中.我正在使用hibernate.cfg.xml文件,其中Castle是我的代理工厂.
Same issue, same resolution attempts. All of the referenced DLLs are set to copy local and are in the project. I am using a hibernate.cfg.xml file with Castle as my proxy factory.
奇怪的是,仅当我使用SessionFactory创建会话时才会发生这种情况.如果我切换到其他通过FluentNHibernate.SessionSource(PersistenceModel)实例化会话的测试类,则不会收到此错误.
Curiously, this only occurs when I use a SessionFactory to create my Session. If I switch to my other test classes where I instantiate a session via FluentNHibernate.SessionSource (PersistenceModel), I don't receive this error.
这篇关于NHibernate代理异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!