zoukankan      html  css  js  c++  java
  • Nhibernate常见的错误

    1.NHibernate使用3中框架动态代理方式
    (1).Castle框架
    如果使用Castle.DynamicProxy2动态代理,引用NHibernate.ByteCode.Castle.dll程序集并配置proxyfactory.factory_class
    <property name="proxyfactory.factory_class"> NHibernate.ByteCode.Castle.ProxyFactoryFactory,NHibernate.ByteCode.Castle</property>
    (2).LinFu框架
    如果使用LinFu.DynamicProxy动态代理,引用NHibernate.ByteCode.LinFu.dll程序集并配置proxyfactory.factory_class节点为
    <property name="proxyfactory.factory_class"> NHibernate.ByteCode.LinFu.ProxyFactoryFactory,NHibernate.ByteCode.LinFu</property>
    (3).Spring.NET框架
    引用NHibernate.ByteCode.Spring.dll程序集并配置proxyfactory.factory_class节点为
    <property name="proxyfactory.factory_class"> NHibernate.ByteCode.Spring.ProxyFactoryFactory,NHibernate.ByteCode.Spring</property>

    如果配置不正确可能导致异常:

    Unable to load type 'NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu' during configuration of proxy factory class.
    Possible causes are:
    - The NHibernate.Bytecode provider assembly was not deployed.
    - The typeName used to initialize the 'proxyfactory.factory_class' property of the session-factory section is not well formed.

    Solution:
    Confirm that your deployment folder contains one of the following assemblies:
    NHibernate.ByteCode.LinFu.dll
    NHibernate.ByteCode.Castle.dll

    2.影射文件与数据库的字段配置不一致   异常:异常could not load an entity:.....................................

    3.创建SessionFactory工厂时候

        private ISessionFactory GetSessionFactory()
            {
                Configuration confriguration = new Configuration().AddAssembly("DomainModel");            

                 return   confriguration.Configure().BuildSessionFactory();//异常:Could not compile the mapping document: DomainModel.Customer.hbm.xml

            }

       这样是不会抛出异常的:

       private ISessionFactory GetSessionFactory()
            {
                Configuration confriguration = new Configuration().AddAssembly("DomainModel");
                return confriguration.BuildSessionFactory();
            }

    4。影射文件的命名空间

    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="DomainModel" namespace="DomainModel" default-lazy="false">

    如果不加default-lazy="false"的话有可能抛出异常:“NHibernate.ByteCode.Castle.ProxyFactory”的类型初始值设定项引发异常。

    5。至于加不加<mapping assembly="DomainModel"/>这个节点,在笔者的机子上是没有错误的。

  • 相关阅读:
    HDU 1087 Super Jumping! Jumping! Jumping!
    HDU 1159 Common Subsequence
    HDU 1003 Maxsum
    HDU 2604 Queuing
    HDU 2045 不容易系列之(3)—— LELE的RPG难题
    HDU 2501 Tiling_easy version
    HDU 2050 折线分割平面
    HDU 2018 母牛的故事
    HDU 2046 骨牌铺方格
    HDU 2044 一只小蜜蜂...
  • 原文地址:https://www.cnblogs.com/wangchuang/p/2487037.html
Copyright © 2011-2022 走看看