Detailed explanation of the hibernate. cfg. xml configuration file

Source: Internet
Author: User
Tags xml parser
Detailed explanation of the hibernate. cfg. xml configuration file

<! -- The starting line of the standard XML file. Version = '1. 0' indicates the XML version, and encoding = 'gb2312 'indicates the encoding method of the XML file. -->
<? XML version = '1. 0' encoding = 'gb2312 '?>
<! -- Indicates the location of the DTD document for parsing this XML file. DTD is short for document type definition, that is, document type definition. The XML parser uses the DTD document to check the validity of the XML file. Other -->
<! Doctype hibernate-configuration public
"-// Hibernate/hibernate configuration DTD 3.0 // en"
Http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd>
<! -- Declare the start of the hibernate configuration file -->
<Hibernate-configuration>
<! -- Indicates that the following configuration is for session-factory configuration, and sessionfactory is a class in hibernate, which is mainly responsible for saving the configuration information of Hibernate and operations on sessions -->
<Session-factory>
<! -- Configure the database driver. hibernate needs to use the database driver when connecting to the database -->
<Property name = "hibernate. Connection. driver_class"> com. MySQL. JDBC. Driver </property>
<! -- Set the connection URL of the database: JDBC: mysql: // localhost/hibernate. localhost indicates the name of the MySQL server. Here it is the local machine, and hibernate indicates the database name. -->
<Property name = "hibernate. Connection. url"> JDBC: mysql: // localhost/hibernate <! -- Connecting to the database is the user name -->
<Property name = "hibernate. Connection. username"> root </property>
<! -- Connecting to the database is a password -->
<Property name = "hibernate. Connection. Password"> 123456 </property>
<! -- Database connection pool size -->
<Property name = "hibernate. Connection. Pool. Size"> 20 </property>
<! -- Whether to display the SQL statement used by hibernate in the background, and set it to true during development to facilitate errors. when running the program, you can display the SQL statement executed by hibernate on the eclipse console. After the project is deployed, you can set it to false to improve the running efficiency. -->
<Property name = "hibernate. show_ SQL"> true </property>
<! -- JDBC. fetch_size refers to the number of records that hibernate extracts from the database and puts in the JDBC Statement each time. The larger the fetch size is, the less the number of reads to the database, the faster the speed. The smaller the fetch size, the more reads the database, and the slower the speed -->
<Property name = "JDBC. fetch_size"> 50 </property>
<! -- JDBC. batch_size indicates the number of records for each operation during hibernate batch insertion, deletion, and update. The larger the batch size, the less SQL statements are sent to the database for batch operations, the faster the speed. The larger the memory consumption -->
<Property name = "JDBC. batch_size"> 23 </property>
<! -- Whether JDBC. use_scrollable_resultset allows hibernate to use JDBC's scrollable result set. The result set of the paging. It is very helpful for paging settings -->
<Property name = "JDBC. use_scrollable_resultset"> false </property>
<! -- Connection. useunicode: whether to use Unicode when connecting to the database -->
<Property name = "connection. useunicode"> true </property>
<! -- Connection. characterencoding: Specifies the encoding method of the Data Transmission Character Set when connecting to the database. It is best to set the encoding method to GBK. The characters in gb2312 are incomplete. -->
<Property name = "connection. characterencoding"> GBK </property>

<! -- Hibernate. dialect is only the database dialect used by hibernate. It is used to connect to that type of database server. -->
<Property name = "hibernate. dialect"> org. hibernate. dialect. mysqldialect </property>
<! -- Specify the ing file as "hibernate/logs/userinfo. HBM. xml" -->
<Mapping Resource = "org/mxg/userinfo. HBM. xml">
</Session-factory>
</Hibernate-configuration>



<Bean id = "datasource"
Class = "org. Apache. commons. DBCP. basicdatasource"
Destroy-method = "close">
// Connection driver
<Property name = "driverclassname" value = "$ {JDBC. driverclassname}"/>
// Connection URL,
<Property name = "url" value = "$ {JDBC. url}"/>
// Connection username
<Property name = "username" value = "$ {JDBC. Username}"/>
// Connection password
<Property name = "password" value = "$ {JDBC. Password}"/>
</Bean>

<Bean id = "hbsessionfactory"
Class = "org. springframework. Orm. hibernate3.annotation. annotationsessionfactorybean">
<Property name = "datasource" ref = "datasource"/>
<Property name = "configlocation">
// Hibernate configuration file location
<Value> WEB-INF/hibernate. cfg. xml </value>
</Property>
<Property name = "configurationclass"
Value = "org. hibernate. cfg. annotationconfiguration"/>
<Property name = "hibernateproperties">
<Props>
// Generates optimized SQL statements for Oracle Database dialects and specific relational databases
<Prop key = "hibernate. dialect">
Org. hibernate. dialect. oracledialect
</Prop>
// Select the implementation of the hql parser
<Prop key = "hibernate. query. factory_class">
Org. hibernate. hql. Ast. astquerytranslatorfactory
</Prop>
// Whether to print SQL statements on the console
<Prop key = "hibernate. show_ SQL"> true </prop>
// When hibernate. use_outer_join is enabled in the hibernate system parameter, this parameter is used to allow the use of Outer Join to load data in this set.
<Prop key = "hibernate. use_outer_join"> true </prop>
// It is enabled by default and cglib reflection optimization is enabled. Cglib is used to dynamically generate Po bytecode in hibernate. Enabling optimization can speed up the construction of bytecode.
<Prop key = "hibernate. cglib. use_reflection_optimizer"> true </prop>
// Output formatted SQL statements for more convenient viewing
<Prop key = "hibernate. format_ SQL"> true </prop>
// "Useunicode" and "characterencoding" determine whether it performs encode during transmission on the client and server, and how to encode
<Prop key = "hibernate. Connection. useunicode"> true </prop>
// Allows the query cache. Some queries still need to be set as cached.
<Prop key = "hibernate. cache. use_query_cache"> false </prop>
<Prop key = "hibernate. default_batch_fetch_size"> 16 </prop>
// Maximum number of activities in the connection pool
<Prop key = "hibernate. DBCP. maxactive"> 100 </prop>
// How does DBCP process when the connection pool has been exhausted (0 = failed, 1 = waiting, 2 = increasing)
<Prop key = "hibernate. DBCP. whenexhaustedaction"> 1 </prop>
// Maximum waiting time
<Prop key = "hibernate. DBCP. maxwait"> 1200 </prop>
// The maximum number of idle connections when no one connects
<Prop key = "hibernate. DBCP. maxidle"> 10 </prop>
# The following describes the processing of prepared statement.
<Prop key = "hibernate. DBCP. PS. maxactive"> 100 </prop>
<Prop key = "hibernate. DBCP. PS. whenexhaustedaction"> 1 </prop>
<Prop key = "hibernate. DBCP. PS. maxwait"> 1200 </prop>
<Prop key = "hibernate. DBCP. PS. maxidle"> 10 </prop>
</Props>
</Property>
</Bean>

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.