Handling of nhib.pdf configuration files and using multi-database multi-layer architecture ideas (Part 3, with source code)

Source: Internet
Author: User

3. Business logic layer 4. Display Layer

Let's not talk about the two.

The content of the hibernate. cfg. xml configuration file is as follows:

<? XML version = "1.0" encoding = "UTF-8"?>
<Hibernate-configuration xmlns = "urn: nhibernate-configuration-2.2">
<Session-factory name = "nhib.pdf. Test">
<! -- Properties -->
<Property name = "connection. provider"> nhib.pdf. Connection. driverconnectionprovider </property>
<Property name = "connection. driver_class"> nhib.pdf. Driver. sqlclientdriver </property>
<Property name = "show_ SQL"> false </property>
<Property name = "dialect"> nhib.pdf. dialect. mssql2005dialect </property>
<Property name = "use_outer_join"> true </property>
<! -- Mapping Files -->
<! -- <Mapping Assembly = "Novelty. Model"/> -->
</Session-factory>
</Hibernate-configuration>

Finally, come along with a problem encountered in the NHibernate-1.2.0.GA version.

If you are using a NHibernate-1.2.0.GA, the attributes of the persistent class require a virtual issue.

If this parameter is not added, the following error occurs: method get _ (attribute or method name) shocould be virtual.

Because nhib1_1.2.0 uses delayed loading for classes by default, you need to add virtual to the attribute or method name.
In addition, I found a blog (see references 7) and gave an explanation in English! Try to translate it, or you can directly read the original text!

1. You may want to follow the exception suggestions andAdd virtual to all your attributes to ensure that your class is not sealed ).Obviously, if you think you want to take advantage of the characteristics of the delayed loading agent, you should do so. However, if you have a base class that can be inherited, or it may only enclose you: A "transparent" persistence layer framework defines how you design some aspects of your valuable classes. Then the second and third items are selected. Both of them involve changes that support old behaviors.

2. for a specific class to change the delayed loading proxy settings, you may need to add a lazy = 'false' attribute to mapping elements. This may look like the following settings:
<Class
Name = "northwindclasses. Category, northwindclasses"
Table = "categories"
Lazy = "false"
>

3. to change the delayed loading proxy settings for all classes in a specific ing file, you may add a lazy = 'false' attribute to the <Hibernate-mapping xmlns = "urn: nhibernate-mapping-2.0" default-Lazy = "false">
 
Unfortunately, if each of your classes corresponds to a

Added on June 23, May 17: Cheney commented that adding the upper and lower settings in the configuration file can solve this problem. That is to say, I don't want to use the features of delayed loading of the agent .:)
<Property name = "use_proxy_validator"> false </property>
Thank you for your advice!
I found another hibernate team's Sergey on the Forum and said: Do not disable verification. either declare the member as virtual, or set the delayed loading of the wrong class to false. verification is disabled only when no error is reported.
Originally don't disable the validation. Either declare the Members virtual, or set lazy = "false" for the failing class. Disable the validation only after it doesn't report any errors.
:

The other two parts:
Handling of nhib.pdf configuration files and using multi-database multi-layer architecture (Part 1)
Http://blog.csdn.net/scucj/archive/2007/05/16/1610858.aspx
Handling of nhib.pdf configuration files and using multi-database multi-layer architecture (Part 2)
Http://blog.csdn.net/scucj/archive/2007/05/16/1610860.aspx

The full text is over!

Supplement:
I suggest you download the source code of a simple solution! Although the three parts add two supplements, the source code of the solution is clearer!

The references are as follows:
(1) initial application development based on nhib.pdf:
Http://www.cnblogs.com/terrylee/archive/2006/02/16/331978.html
(2) flexible configuration of nhib.pdf:
Http://www.cnblogs.com/renrenqq/archive/2006/08/02/466056.html
(3) Chapter 1 single pattern ):
Http://terrylee.cnblogs.com/archive/2005/12/09/293509.html
(4) execute the SQL statement in nhib.pdf:
Http://www.cnblogs.com/oldhorse/archive/2006/07/08/445958.html
(5) ilist <t> to Dataset:
Http://www.cnblogs.com/yyw84/archive/2006/08/15/463480.html
(6) object-oriented nhibbench Data Query Language-hql
Http://www.cnblogs.com/me-sa/archive/2007/04/09/705323.html
(7) exceptions related to nhibernate1.2 delayed loading and invalidproxytypeexception
Http://blog.csdn.net/lulustray/archive/2007/04/20/1571506.aspx
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.