The following types may not be used as proxies 异常

如标题,我解决的方法用了下面的第三种方法.

下面的文章转载于http://hi.baidu.com/zsea/blog/item/7d999e3d8a54c203baa1678d.html

一、Test.Model.Person.hbm.xml(2,2): XML validation error: 未能找到元素“urn:nhibernate-mapping-2.0:hibernate-mapping”的架构信息。

       将2.0改为2.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

         类配置文件中Class的Lazy改为false
         网上搜到的三种解决方案:
        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.
### 解析HTTP 406 Not Acceptable 错误 当遇到HTTP 406 Not Acceptable错误时,这通常意味着服务器无法根据客户端请求中的Accept头字段找到合适的内容类型来响应。此问题在通过代理服务器和防火墙配置不当的情况下尤为常见。 #### 客户端与服务器之间的内容协商机制 为了确保正确处理不同类型的资源,HTTP协议引入了内容协商的概念。客户端可以通过设置`Accept`头部告知服务器能够接受的内容类型(如HTML, JSON, XML等),而服务器会依据这些信息选择最匹配的数据格式进行回应[^1]。 #### 防火墙及代理服务器的影响因素分析 防火墙或某些企业级网络环境下的代理设备可能会修改原始HTTP请求报文,特别是涉及到安全策略的应用场景下,它们有可能过滤掉特定的MIME-Type或者改变原有的Accept头部定义。这种行为可能导致原本合法合理的请求变得不再满足目标站点的要求,从而触发406错误码。 #### 排查与解决方案建议 针对上述情况,可以从以下几个方面着手排查并解决问题: - **审查代理配置**:确认所使用的代理服务是否会对传出流量实施严格的媒体类型限制;如果存在此类规则,则应适当放宽以允许更多种类的数据传输。 - **调整浏览器/应用程序设置**:对于自定义开发的应用程序而言,开发者应当仔细核对发出请求时携带的所有HTTP头部参数,尤其是那些涉及内容偏好的选项,比如`Accept-Language`, `Accept-Encoding`以及最重要的`Accept`本身。必要时手动指定期望接收的结果形式。 - **联系网站管理员**:有时即使本地一切正常,也可能因为远程主机端的原因造成不兼容现象。此时不妨尝试联系对方的技术支持团队获取进一步的帮助和支持。 ```python import requests headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)', 'Accept': '*/*', # 尝试使用通配符表示可以接受任何形式的内容 } response = requests.get('https://example.com/resource', headers=headers) if response.status_code == 406: print("仍然收到406错误,请检查其他可能原因") else: print(f"成功获取到{len(response.content)}字节的数据") ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值