Hibernate configuration properties

4.4. Optional configuration properties

There are a number of properties that can be used to control the behavior of Hibernate at runtime. They are all optional and have appropriate default values.

Warning: some of these properties are "system-level" ". System-level properties can be set by java -Dproperty=value or hibernate.properties, but not by the other methods described above.

Table 4.3. Hibernate configuration properties

Property name usage
hibernate.dialect A Hibernate Dialect class name allows Hibernate to target Generates optimized SQL for a specific relational database. The
value full.classname.of.Dialect

hibernate.show_sql outputs all SQL statements to the console. The
value is true | false

hibernate.default_schema In the generated SQL, the given schema/tablespace Append to the table name without fully qualified name.
Value SCHEMA_NAME

hibernate.default_catalog In the generated SQL, append the given catalog to the table name without fully qualified name.
Value CATALOG_NAME

hibernate.session_factory_name After the SessionFactory is created, it will Automatically use this name to bind to JNDI. The
value is jndi/composite/name

hibernate.max_fetch_depth sets the maximum depth for the outer join fetch tree of unidirectional associations (one-to-one, many-to-one). A value of 0 means that the default outer join fetch will be turned off. The
recommended value is 0 A value between 3

hibernate.default_batch_fetch_size sets the default number of batch fetches associated with Hibernate. The
recommended values ​​are 4, 8, and 16

hibernate.default_entity_mode specifies the default entity representation mode for all sessions opened by this SessionFactory .values
​​dynamic-map, dom4j, pojo

hibernate.order_updates Force Hibernate to sort SQL updates according to the primary key of the updated data. Doing so will reduce transaction deadlocks in highly concurrent systems.
Values ​​true | false

hibernate.generate_statistics If enabled, Hibernate will collect statistics useful for performance tuning.
Values ​​true | false

hibernate.use_identifer_rollback If enabled, identity properties generated when objects are deleted will be reset to their default values
.value true | false

hibernate.use_sql_comments If enabled, Hibernate will generate comments in SQL that are helpful for debugging. The default value is false. The value is
true | false

Table 4.4. Hibernate JDBC and connection properties

Property name usage
hibernate.jdbc.fetch_size Non-zero value, specifies the size of the number of JDBC fetches (call Statement.setFetchSize()).
hibernate.jdbc.batch_size Non-zero value, allows Hibernate Batch update using JDBC2. The
recommended value is between 5 and 30

hibernate.jdbc.batch_versioned_data If you want your JDBC driver to return the correct row count from executeBatch(), then set this property to true (enable this option is generally safe). Also, Hibernate will use batch DML for autoversioned data. The default value is false.
eg. true | false

hibernate.jdbc.factory_class selects a custom Batcher. Most applications do not need this configuration Properties.
eg. classname.of.Batcher

hibernate.jdbc.use_scrollable_resultset Allows Hibernate to use JDBC2 scrollable result sets. This option is only necessary when using a user-supplied JDBC connection, otherwise Hibernate will use the connection metadata.
Values ​​true | false

hibernate.jdbc.use_streams_for_binary Use streams (system-level property) when JDBC reads and writes binary (binary) or serializable (serializable) types.
Values ​​true | false

hibernate.jdbc.use_get_generated_keys After the data is inserted into the database, it is allowed to use JDBC3 PreparedStatement.getGeneratedKeys() to get the keys (keys) generated by the database. Requires JDBC3+ driver and JRE1.4+, if your database driver has problems using Hibernate's identity generator, please set this value to false. By default, the connection metadata will be used to determine the driver's capabilities.
Take The value true|false

hibernate.connection.provider_class defines the class name of the ConnectionProvider, which is used to provide JDBC connections to Hibernate. The
value classname.of.ConnectionProvider

hibernate.connection.isolation sets the JDBC transaction isolation level. See java.sql.Connection to understand the specific meaning of each value, but please note that most databases do not support all isolation levels.
Values ​​1, 2, 4, 8

hibernate.connection.autocommit allow cached JDBC connections to enable autocommit (not recommended) )
.value true | false

hibernate.connection.release_mode specifies when Hibernate releases the JDBC connection. By default, the JDBC connection is not released until the Session is explicitly closed or disconnected. For application server JTA data sources, you should use after_statement , so that the connection will be actively released after each JDBC call. For non-JTA connections, it is reasonable to use after_transaction to release the connection at the end of each transaction. auto selects after_statement for JTA and CMT transaction strategies, and JDBC transaction strategy Select after_transaction.value
on_close | after_transaction | after_statement | auto

hibernate.connection.<propertyName> Pass the JDBC property propertyName to DriverManager.getConnection().
hibernate.jndi.<propertyName> Pass the property propertyName to JNDI InitialContextFactory.
Table 4.5. Hibernate Cache Properties

Property Name Purpose
hibernate.cache.provider_class Custom CacheProvider class name.
Value classname.of.CacheProvider

hibernate.cache.use_minimal_puts At the expense of frequent read operations, optimize the second level cache to minimize writes Action. In Hibernate 3, this setting is very useful for clustered caches, which are enabled by default for clustered cache implementations.
A value of true|false

hibernate.cache.use_query_cache enables query caching, individual queries still need to be made cacheable. A
value of true|false

hibernate.cache.use_second_level_cache can be used to disable the use of second-level caching entirely. The class specified in the mapping definition <cache> will enable the second level cache by default. The
value is true|false

hibernate.cache.query_cache_factory The custom class name that implements the QueryCache interface, the default is the built-in StandardQueryCache. The
value is classname.of. QueryCache

hibernate.cache.region_prefix The prefix of the second-level cache region name. The
value of prefix

hibernate.cache.use_structured_entries forces Hibernate to store data in the second-level cache in a more user-friendly format. The
value is true|false

. Table 4.6. Hibernate transaction properties

Property Name usage
hibernate.transaction.factory_class A class name of TransactionFactory, used for Hibernate Transaction API (default is JDBCTransactionFactory).
Value classname.of.TransactionFactory

jta.UserTransaction A JNDI name used by the JTATransactionFactory to get the JTA UserTransaction from the application server.
Value jndi/composite/name

hibernate.transaction.manager_lookup_class A class name of TransactionManagerLookup - when using JVM level caching, or when using hilo generation in a JTA environment This class is required when the transaction is used. The
value classname.of.TransactionManagerLookup

hibernate.transaction.flush_before_completion If enabled, the session will be automatically flushed (flush) after the transaction is completed. (Useful when Hibernate and CMT are used together.) The
value is true | false

hibernate.transaction.auto_close_session If enabled, the session will be automatically closed after the transaction is completed. (Useful when Hibernate and CMT are used together.)
Value true | false

Table 4.7. Other properties

Property name usage
hibernate.query.factory_class Select the implementation of the HQL parser. Take the
value org.hibernate.hql.ast.ASTQueryTranslatorFactory or org.hibernate.hql.classic.ClassicQueryTranslatorFactory

hibernate.query.substitutions maps the symbols in the Hibernate query to the symbols in the SQL query (the symbols may be function names or constant names).
The values ​​hqlLiteral=SQL_LITERAL, hqlFunction=SQLFUNC

hibernate.hbm2ddl.auto automatically converts the SessionFactory to the The DDL of the database schema is exported to the database. When using create-drop, when the SessionFactory is explicitly closed, the database schema will be dropped. The
value update | create | create-drop

hibernate.cglib.use_reflection_optimizer enables CGLIB to replace the runtime reflection mechanism ( System-level property). Reflection is sometimes useful for debugging. Note that even with this optimization turned off, Hibernate still requires CGLIB. You cannot set this property in hibernate.cfg.xml.
Value true | false

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327074620&siteId=291194637