Nhibernate 1.2版本的配置(vs2005)

原来一直使用vs2003和Nhibernate1.02,项目需要升级到.net2.0并开发WinFrom,相应的Nhibernate也需要升级到 1.2以上版本。
开始配置就遇上了一系列的问题,记录在此,希望对各位有用。
问题一:未能找到元素“urn:nhibernate-mapping-  2.0:hibernate-mapping
解决方案:将类的mapping xml的“urn:nhibernate-mapping-  2.0"中的2.0替换为2.2
问题二:The dialect was not set. Set the property hibernate.dialect.
解决方案:明明在×××.exe.config中已经配置了Nhibernate的相关参数,为什么会出现这样的错误提示呢?原来是没有将其自动复制到程序的运行目录。选中该文件,查看属性,其中第一项选择为“始终复制”,问题解决。看样子vs2005用的还是少啊。
问题三:method get_Id should be virtual
解决方案:原因是Nhibernate1.2使用了延迟加载。参照其文档,解决方案有三种。
修改配置的xml,将类定义增加lazy=false;修改Nhibernate全局配置,增加default-lazy="false";将属性的存取修改为Virtual,并且该类不能为sealed。

相关原文如下:

1.  You can follow the advice of the exception and add "virtual" to all of your properties, and make sure your class is non-sealed.  Obviously you'll want to do this if you think you might want to take advantage of the lazy-initializing proxy feature.  However, changing your classes may not be practical or advisable if you have a legacy codebase, or it may just bother you that a "transparent" persistence framework is dictating how you design certain aspects of your value classes.  That's where Options 2 and 3 come in.  Both of those involve changing back to the old behavior.
 
2.  To change the lazy-initialization proxy setting for a specific class, you can add a "lazy='false'" attribute to the <class> mapping element.  This might look something like:
 
<class 
    name="NorthwindClasses.Category, NorthwindClasses"
    table="Categories"
     lazy ="false"
>
 
3.  To change the lazy-initialization proxy setting for all classes in a given mapping file, you can add a "default-lazy='false'" attribute to the <hibernate-mapping> element, as follows:
 
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"  default-lazy ="false">
 
Unfortunately, Option 3 doesn't really help you much if you do one <class> mapping per <hibernate-mapping> file, a practice which I personally follow and recommend.  It's too bad, but there doesn't seem to be any way to set this default in the <nhibernate> global configuration.  But if you do happen to have all of your <class>'s in one .hbm.xml file, "default-lazy" can help you out.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值