Nhib.pdf connects to the Oracle database. The primary key ID is used to analyze the number of I/O accesses to the database when the sequence is generated.

Source: Internet
Author: User

The primary key ID was originally intended to be generated using a trigger, because the program can insert a data entry only once I/O.

As shown in the following figure, assigned cannot be changed to native. In the configuration, the program generates the ID. However, after Oracle accepts the message inserted, the trigger automatically replaces the ID with the sequence, therefore, the program cannot obtain the primary key ID of the inserted object. Therefore, it is changed to the sequence creation ID specified in the configuration file, to view the SQL statements it generates and the number of I/O times it connects to the database, I used nhibernateprofiler and SQL Server Profiler for detection. Oracle did not find a good tool for detecting the connection to SQL, therefore, it was detected by MSSQL detection tools. I was confused when I used nhibernateprofiler to detect the generation of SQL statements. Since a series of executions shared sessions, this tool only displays one session and lists which sqls it generates, let me think that it is just an IO and get the entire query and operation. The default latency loading of Nhibernate seems to be if there are no identical objects in the same session, and then get the objects from the database, however, other objects inside the object will be loaded at a time delay, and the SQL statement detected by the object is not obtained by the real database. For example, the query is parameterized, however, nhibernateprofiler does not elaborate on the parameters to be queried. This is not clear during the creation of the query sequence and the SQL statement passed to the inserted object, I used SQL Server Profiler to confirm this.

The configuration file is as follows:

Testseq. HBM. xml

<? XML version = "1.0" encoding = "UTF-8"?>
<Hibernate-mapping xmlns = "urn: nhibernate-mapping-2.2" assembly = "domainmodel" namespace = "domainmodel">
<Class name = "domainmodel. Entities. testseq, domainmodel" table = "testseq">
<ID name = "ID" column = "ID" type = "int">
<Generator class = "assigned"> </generator>
</ID>
<Property name = "name" column = "name" type = "string"/>

</Class>
</Hibernate-mapping>

 

The configuration file after IDs are generated for the specified sequence is as follows:

Testseq. HBM. xml

<? XML version = "1.0" encoding = "UTF-8"?>
<Hibernate-mapping xmlns = "urn: nhibernate-mapping-2.2" assembly = "domainmodel" namespace = "domainmodel">
<Class name = "domainmodel. Entities. testseq, domainmodel" table = "testseq">
<ID name = "ID" column = "ID" type = "int">
<Generator class = "sequence">
<Param name = "sequence"> testseq1 </param>
</Generator>
</ID>
<Property name = "name" column = "name" type = "string"/>

</Class>
</Hibernate-mapping>

 

Program C # code execution database statement:

 

VaR c = domainservice. addtestseq (New domainmodel. Entities. testseq () {name = datetime. Now. tostring ()});
VaR A = domainservice. gettestbyid ("002 ");
VaR B = domainservice. gettestbyid ("003 ");

 

With nhibernateprofiler:

The parameterized SQL statement is not displayed, and the executed SQL statement is displayed, but the number of times the database is connected cannot be seen. So I connected to SQL Server and checked the connected SQL with SQL Server Profiler. Because MSSQL does not have a sequence, it can only be seen when sharing the same session lifecycle, the number of SQL queries detected by the database for all database operations,

The configuration file is as follows:

<ID name = "ID" column = "ID" type = "int32" unsaved-value = "0">
<Generator class = "native"> </generator>
</ID>

All others are the same,

C # The Code is as follows:

 

VaR A = domainservice. gettestbyid3 (1 );
VaR a2 = domainservice. gettestbyid3 (1 );
VaR B = domainservice. gettestbyid3 (2 );
Object O2 = domainservice. addtest (New domainmodel. Entities. Test () {name = "AB "});

 

With nhibernateprofiler:

Use SQL Server Profiler to detect the following:

It can be seen that there are three open and close operations on the database. Therefore, although Nhibernate shares a session, some operations are like a whole execution, and only query operations are performed, nhibernateprofiler displays the number of SQL records queried only when all the SQL statements for query operations are completed or when database insertion is performed, however, the nhibernateprofiler actually connects to and closes the database query operation for each record in the short SQL interface. When the sequence is used to create the primary key ID, The nhibernateprofiler display is also the query operation for the two databases.

He is not familiar with Nhibernate. Li yongjing's Nhibernate series of articles are not bad. He needs to learn more, and NH3. he has more features and functions, however, I am still interested in nhib.pdf's second-level cache extension because it directly affects the end user and I hope I will be more familiar with it in the future.

Related Article

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.