Hibernate profile and use rules

xiaoxiao2021-03-06  109

Hibernate profile and use rules - reprint

Hibernate profile and use rules

Hibernate's Introduction Hibernate is an O / R Mapping of an open source code that performs a lightweight object package for JDBC, allowing Java programmers to operate the database as you want to use objects to manipulate the database. Hibernate's persistence layer solution is frequently interacting with the backend database and makes interaction more effective, 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. Install hibernate

Download the Hibernate source code, you can download from the following URL: http://prdownloads.sourceforge.net/Hibernate/? Sort_by = Date & Sort = DESC Unzip to the directory you want to put, (it is best not to use the application development directory, Because Hibernate features, in the JAR package it provides, if you put the source files together, you will make code confusing) to put the third party provided by the Hibernate2.jar and the Lib directory to the application you want to develop. The configuration of Hibernate is briefly introduced in the LIB directory. For details, please refer to the Hibernate Chinese manual.

Hibernate profiles 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. . Brief description of Hibernate configuration properties (there is template in hibernate.properties, modified action)

Hibernate.Query.Substitutions 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 Similar database operations, with 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 different for different databases declaration of Hibernate dialect class Name, allows Hibernate to use certain specific database platform features. hibernate.connection.driver_class is JDBC driver is JDBC hibernate.connection.url of URLhibernate.connection.username database user name hibernate.connection.password database user password hibernate.connection.pool_size 1 and hibernate.statement_cache.size 25 which is self Hibernate Configuration parameters of the connection pool, 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, you can help you solve the problem. Hibernate.connection.ission 4 Specifies the isolation level of the database, often different databases have their own quarantine levels, not necessarily Hibernate settings, so you don't have to take 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.

转载请注明原文地址:https://www.9cbs.com/read-99432.html

New Post(0)