Detailed explanation of Hibernate configuration file hibernate.cfg.xml

Keywords: Hibernate Database JDBC xml

The starting line of a standard XML file, version='1.0'indicates the version of the XML, encoding='gb2312' indicates how the XML file is encoded
<?xml version='1.0' encoding='Utf-8'?>
Indicates the location of the DTD document where the XML file is parsed. DTD is the abbreviation for Document Type Definition, which is the definition of the document type. The XML parser uses the DTD document to check the validity of the XML file.hibernate.sourceforge.net/hibernate-configuration-3.0dtd can be found in the ~~/hibernate-release-5.2.10.Final/project/hibernate-core/src/test/resources directory in the Hibernate package
<!DOCTYPE hibernate-configuration PUBLIC 
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
Declare the beginning of the Hibernate configuration file
<hibernate-configuration>
Indicates that the following configuration is for session-factory configuration, SessionFactory is a class in Hibernate that is responsible for saving configuration information for HIbernate and for manipulating Sessions
<session-factory>
Configure the driver for the database Hibernate needs to use when connecting to the database
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver </property>
Set the connection url:jdbc:mysql://localhost/hibernate for the database, where localhost represents the MySQL server name, where native, hibernate is the database name
<property name="hibernate.connection.url">jdbc:mysql://localhost/hibernate </hibernate>
Connecting to the database is a user name
<property name="hibernate.connection.username">root </property>
Connecting to the database is a password
<property name="hibernate.connection.password">123456 </property>
Size of database connection pool
<property name="hibernate.connection.pool.size">20 </property>
Whether to display the SQL statements used by Hibernate in the background, set to true at development time for errors, and allow Hibernate to execute Sql statements when the program is running in the Eclipse console.Project deployment can be set to false to improve operational efficiency
<property name="hibernate.show_sql">true </property>
jdbc.fetch_size is the number of records that Hibernate fetches from the database and puts into the JDBC Statement each time.The larger the Fetch Size setting, the fewer times the database is read, the faster the speed is, the smaller the Fetch Size, the more times the database is read, the slower the speed is
<property name="jdbc.fetch_size">50 </property>
jdbc.batch_size is the number of records per operation when Hibernate is inserted, deleted, and updated in bulk.The larger the Batch Size, the fewer times batch operations send Sql to the database, the faster it will be, and the more memory it will consume
<property name="jdbc.batch_size">23 </property>
Whether jdbc.use_scrollable_resultset allows Hibernate to use JDBC's scrollable result set.Paging result set.Settings for paging are very helpful
<property name="jdbc.use_scrollable_resultset">false </property>
Whether to use Unicode encoding when connecting to a database with connection.useUnicode
<property name="Connection.useUnicode">true </property>
The transmission character set encoding for data when connection.characterEncoding connects to a database, preferably ut8, with incomplete characters in gb2312
<property name="connection.characterEncoding">UTF-8 </property>
hibernate.dialect is only a database dialect used by Hibernate to connect to that type of database server.
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect </property>
#Specifies that the mapping file is "hibernate/ch1/UserInfo.hbm.xml"
<mapping resource="org/mxg/UserInfo.hbm.xml">
Symmetric End Label


<bean id="dataSource"  
  class="org.apache.commons.dbcp.BasicDataSource"  
  destroy-method="close">
Connection Driver
<property name="driverClassName" value="${jdbc.driverClassName}" />
Connect 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 profile location
<value>WEB-INF/hibernate.cfg.xml </value>  
  </property>  
  <property name="configurationClass"  
  value="org.hibernate.cfg.AnnotationConfiguration" />  
  <property name="hibernateProperties">  
  <props>
Specific relational databases generate optimized SQL for the dialect of an oracle Database
<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 in the console
<prop key="hibernate.show_sql">true </prop>
When hibernate.use_outer_join is opened in the Hibernate system parameter, it is used to allow outer join to load data for this collection.
<prop key="hibernate.use_outer_join">true </prop>
By default, cglib reflection optimization is enabled.Cglib is used to dynamically generate PO byte codes in Hibernate. Turning on optimization can speed up byte code construction
<prop key="hibernate.cglib.use_reflection_optimizer">true </prop>
Output formatted sql for easier viewing
<prop key="hibernate.format_sql">true </prop>
"useUnicode" and "characterEncoding" determine whether and how it will be Encode d during client-side and server-side transport
<prop key="hibernate.connection.useUnicode">true </prop>
Allows queries to be cached, and individual queries still need to be set as cacheable.
<prop key="hibernate.cache.use_query_cache">false </prop>  
  <prop key="hibernate.default_batch_fetch_size">16 </prop>
Maximum number of activity for connection pool
<prop key="hibernate.dbcp.maxActive">100 </prop>
What will DBCP do when connections in the connection pool have been exhausted (0 = failed, 1 = waiting, 2 = growing)
<prop key="hibernate.dbcp.whenExhaustedAction">1 </prop>
Maximum Wait Time
<prop key="hibernate.dbcp.maxWait">1200 </prop>
Maximum number of connections idle when no one is connected
<prop key="hibernate.dbcp.maxIdle">10 </prop>  
##The following is the processing of prepared statement, the same as above.    
<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>  




Label

Posted by colandy on Wed, 26 Jun 2019 10:11:49 -0700