初次接触NHibernate遇到的问题及解决方法
2009-03-07 23:31
435 查看
今天初学NHibernate, 试着做了一个demo,遇到两个问题,在网上查了一下,解决了一个,另外一个靠经验解决了.
问题1 出现Could not compile the mapping document
问题出在你所使用的NHibernate的版本与你在配置文件中所设的不一致,例如,在配置文件中有如下信息,
<section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
而你所引用的NHibernate.dll可能是最新的版本,于是就会出现这个问题.这时有一个简单的办法,就是到你存放NHibernate的文件夹下找到一个名为NHibernate.Examples.dll的文件,以文本文件打开,复制里面所有的内容,覆盖掉你配置文件里的所有内容,即可解决Could not compile the mapping document的问题.当然,别忘了更改数据库连接字符串!
问题2 The following types may not be used as proxies:
Test.Model.Person: method set_Id should be virtual
Test.Model.Person: method get_Name should be virtual
Test.Model.Person: method set_Name should be virtual
Test.Model.Person: method get_Id should be virtual
网上搜到的三种解决方案:
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.
问题1 出现Could not compile the mapping document
问题出在你所使用的NHibernate的版本与你在配置文件中所设的不一致,例如,在配置文件中有如下信息,
<section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
而你所引用的NHibernate.dll可能是最新的版本,于是就会出现这个问题.这时有一个简单的办法,就是到你存放NHibernate的文件夹下找到一个名为NHibernate.Examples.dll的文件,以文本文件打开,复制里面所有的内容,覆盖掉你配置文件里的所有内容,即可解决Could not compile the mapping document的问题.当然,别忘了更改数据库连接字符串!
问题2 The following types may not be used as proxies:
Test.Model.Person: method set_Id should be virtual
Test.Model.Person: method get_Name should be virtual
Test.Model.Person: method set_Name should be virtual
Test.Model.Person: method get_Id should be virtual
网上搜到的三种解决方案:
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.
相关文章推荐
- 在无显示器状态下树莓派初次接触遇到的问题和解决方法
- 学习NHibernate时遇到的问题解决方法
- 初次体验百度eCharts遇到的问题和解决方法
- vue项目中做编辑功能传递数据时遇到问题的解决方法
- iOS真机编译遇到的一些问题及解决方法
- CGAL配置后使用时遇到的一些问题及解决方法
- 配置WebSite的IIS时遇到的问题与解决方法
- JS中常遇到的浏览器兼容问题和解决方法
- 编译LDD第三版中scullc代码时遇到的问题及解决方法
- Ubuntu14.04系统下VSCode+Latex遇到问题及相应解决方法
- ubuntu下mysql可能遇到的问题及解决方法
- rails项目迁移中遇到的问题及解决方法
- 离线安装ADT 23.0.4遇到的问题与解决方法
- Oracle BPM开发中遇到的一些问题和解决方法
- 嵌入式linux(内核为linux 2.6.30.4)开发中遇到的一些问题解决方法
- MAC 下安装opencv遇到问题的解决方法(安装homebrew, wget)
- cocos2dx android 接入移动MM 遇到问题及解决方法
- 在DELL服务器上安装VMware ESXi 5.0时遇到网卡问题的解决方法
- VM 安装Linux虚拟服务器:环境搭建遇到:《Linux “ifconfig”看不到inet address》问题--解决土方法