Hibernate profile and use rules
1. Introduction to Hibernate, Hibernate is an O / R Mapping of an open source, which makes a lightweight object package for JDBC, allowing Java programmers to operate the database as you want to use objects to manipulate the database.
2. Hibernate's persistent layer solutions interacts frequently with the backend database and makes interaction more efficient and fast, and enterprise application developers have created a "persistence layer" between applications and databases. This database is responsible for storing data applied to the database, also responsible for data retrieval, update, and deletion. In J2EE-based enterprise applications, the Java class that makes up this persistence layer can map both objects to data or map data to objects. The lasting layer is simple, but this relationship is often difficult to establish, because the object or the lower database structure is complex, it is difficult to make the relationship of the relationship table to the relationship of the lasting object, which is mainly reflected in the multi-table. The relationship cannot be mapped directly to the map of persistent objects. It may be a table mapping multiple persistent objects. It is possible that multiple tables maps a persistent object, more likely to map some of the tables to a persistent object, and Some fields are mapped to other persistent objects. Hibernate is an open source object / with persistence and query-related framework. Hibernate helps the creation of a lasting object of a normal Java object model, allowing persistent objects to have complex structures such as mixing types, collection, and attributes, but also users The type of definition. These persistent objects now can effectively reflect the complex structure of the underlying database mode. In order to improve efficiency, Hibernate includes some strategies, such as multi-optimization with the database, including the cache of the object, the acquisition of the effective external connection, and the execution of the SQL statement when necessary.
3. Install Hibernate
o Download the Hibernate source version, you can download: http://prdownloads.sourceforge.net/hibernate/? sort_by = Date & Sort = DESC
o Decompression to the directory you want to put, (it is best not to use the application development directory, because hibernate's function is in the JAR package it provides, if the source file is put together, it is bound to cause code confusion)
o puts the JAR package provided by the third party in the hibernate2.jar and the lib directory to the lib directory of the application you want to develop.
4. Configure Hibernate to briefly describe the various configuration properties of Hibernate, please refer to the Hibernate Chinese manual.
o Hibernate profile can have two formats, one is hibernate.properties, and the other is hibernate.cfg.xml. The latter is slightly convenient. When adding an HBM mapping file, it can be added directly in hibernate.cfg.xml, and it is not necessary to join in the initialization code like hibernate.properties. For different applications, the storage location of the Hibernate configuration file is also different. If it is a web application, put the configuration file in a web-inf / classsess / directory; if it is a JRE environment, place the configuration file in the root directory. .
o Hibernate configuration properties (there is template in hibernate.properties, modifying)
§ Hibernate.query.substitudes True 1, false 0, yes 'y', no 'n' This configuration means that when you enter True in Hibernate, Hibernate will turn into 0 insert the database when you enter False in Hibernate. When Hibernate is converted to 1 inserted into the database, the following Y, N Tame § Database operation related properties, using mysql as an example] Hibernate.DiaLect Net.sf.hibernate.diaalect.driver_class org.gjt .mm.mysql.Driverhibernate.connection.driver_class com.mysql.jdbc.Driverhibernate.connection.url jdbc: mysql: ///testhibernate.connection.username roothibernate.connection.password hibernate.dialect statements for different databases of different dialects Hibernate The class name allows Hibernate to use certain specific database platform features. Hibernate.Connection.driver_class is the driver of JDBC hibernate.connection.URL is a jdbc urlhibernate.connection.username database Username Hibernate.Connection.Password database user password
§ Hibernate.connection.pool_size 1 and hibernate.Statement_Cache.size 25 This is the configuration parameters of the Hibernate comes with the connection pool, which will be adopted by default. Hibernate This connection pool is a very original very simple connection pool. If you use Hibernate in your project, it is recommended to prefer the App Server connection pool, select the DBCP connection pool of the Hibernate tape. The self-contained connection pool should be selected as the end.
§ Hibernate.show_sql True Shows Hibernate to the SQL of the database, when you debug hibernate, let Hibernate print SQL statements to help you solve the problem.
§ Hibernate.Connection.ission 4 Specifies the isolation level of the database, often different databases have their own quarantine levels, but must not be able to manage it.
§ Hibernate.jdbc.Fetch_size 50 and hibernate.jdbc.batch_size 25 Fetch Size is the number of records removed from the database when setting the JDBC's Statement read data. The larger the FETCH Size, the less the number of times the database is, the faster the speed; the smaller the fetch size, the more the number of times the database is, the slower the speed. However, not all databases support Fetch size feature, such as MySQL. Batch size is a batch size when setting a bulk deletion, bulk update, and batch insertion, a bit equivalent to setting the Buffer buffer size. The larger the Batch size, the less the number of times the quantity is sent to the database, the faster the speed.
§ Hibernate.jdbc.use_scrollable_Resultset True Set whether you can use the rolling result set of JDBC2.0 specification, which has a certain role in Hibernate's paging display, which is OK. § Hibernate.cglib.use_reflection_optimizer false Open by default, enabled CGLIB reflection optimization. CGLIB is used to dynamically generate PO bytecodes in Hibernate, and open optimization can speed up the speed of the word code structure.
§ hibernate.transaction.factory_class net.sf.hibernate.transaction.JTATransactionFactoryhibernate.transaction.factory_class net.sf.hibernate.transaction.JDBCTransactionFactoryHibernate package is lightweight object of the JDBC, Hibernate itself does not have the Transaction processing functions, Hibernate of Transaction is actually a package of JDBC Transaction, or a package of JTA Transaction. If you are not configured, use JDBCTRANSACTION by default.
5. Remarks Here are only some common hibernate properties, and about other aspects of property configuration, see "Hibernate Chinese Reference Manual", Hibernate's Chinese Website and Hibernate's official website.