`
missall
  • 浏览: 125189 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Hibernate参数设置一览表

阅读更多

出处:http://www.blogjava.net/i369/articles/194855.html

1、Hibernate JDBC属性

属性名 用途
hibernate.connection.driver_class jdbc驱动类
hibernate.connection.url jdbc URL
hibernate.connection.username 数据库用户
hibernate.connection.password 数据库用户密码
hibernate.connection.pool_size 连接池容量上限数目

注:使用C3P0的properties样例代码:

<!-- <br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->hibernate.connection.driver_class = org.postgresql.Driver
hibernate.connection.url = jdbc:postgresql://localhost/mydatabase
hibernate.connection.username = myuser
hibernate.connection.password = secret
hibernate.c3p0.min_size=5
hibernate.c3p0.max_size=20
hibernate.c3p0.timeout=1800
hibernate.c3p0.max_statements=50
hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect


2、Hibernate的数据源属性

属性名 用途
hibernate.connection.datasource 数据源JNDI名字
hibernate.jndi.url JNDI提供者的URL (可选)
hibernate.jndi.class JNDI InitialContextFactory (可选)
hibernate.connection.username 数据库用户 (可选)
hibernate.connection.password 数据库用户密码 (可选)

注:应用程序服务器JNDI数据源的hibernate.properties 样例代码:

<!-- <br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->hibernate.connection.datasource = java:/comp/env/jdbc/test
hibernate.transaction.factory_class = \
    org.hibernate.transaction.JTATransactionFactory
hibernate.transaction.manager_lookup_class = \
    org.hibernate.transaction.JBossTransactionManagerLookup
hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect


3、Hibernate配置属性(可选)

属性名 用途
hibernate.dialect 一个Hibernate Dialect 类名允许Hibernate针对特定的关系数据库生成优化的SQL.

取值 full.classname.of.Dialect

hibernate.show_sql 输出所有SQL语句到控制台.

取值 true | false

hibernate.format_sql 在log和console中打印出更漂亮的sql.

取值 true | false

hibernate.default_schema 在生成的SQL中, 将给定的schema/tablespace附加于非全限定名的表名上.

取值 SCHEMA_NAME

hibernate.default_catalog 在生成的SQL中, 将给定的catalog附加于没全限定名的表名上.

取值 CATALOG_NAME

hibernate.session_factory_name SessionFactory 创建后,将自动使用这个名字绑定到JNDI中.

取值 jndi/composite/name

hibernate.max_fetch_depth 为单向关联(一对一, 多对一)的外连接抓取(outer join fetch)树设置最大深度. 值为0 意味着将关闭默认的外连接抓取.

取值 建议在03 之间取值

hibernate.default_batch_fetch_size 为Hibernate关联的批量抓取设置默认数量.

取值 建议的取值为4 , 8 , 和16

hibernate.default_entity_mode 为由这个SessionFactory 打开的所有Session指定默认的实体表现模式.

取值 dynamic-map , dom4j , pojo

hibernate.order_updates 强制Hibernate按照被更新数据的主键,为SQL更新排序。这么做将减少在高并发系统中事务的死锁。

取值 true | false

hibernate.generate_statistics 如果开启, Hibernate将收集有助于性能调节的统计数据.

取值 true | false

hibernate.use_identifer_rollback 如果开启, 在对象被删除时生成的标识属性将被重设为默认值.

取值 true | false

hibernate.use_sql_comments 如果开启, Hibernate将在SQL中生成有助于调试的注释信息, 默认值为false .

取值 true | false


4、Hibernate JDBC和连接(connection)属性

属性名 用途
hibernate.jdbc.fetch_size 非零值,指定JDBC抓取数量的大小 (调用Statement.setFetchSize() ).
hibernate.jdbc.batch_size 非零值,允许Hibernate使用JDBC2的批量更新.

取值 建议取530 之间的值

hibernate.jdbc.batch_versioned_data 如果你想让你的JDBC驱动从executeBatch() 返回正确的行计数 , 那么将此属性设为true (开启这个选项通常是安全的). 同时,Hibernate将为自动版本化的数据使用批量DML. 默认值为false .

eg. true | false

hibernate.jdbc.factory_class 选择一个自定义的Batcher . 多数应用程序不需要这个配置属性.

eg. classname.of.Batcher

hibernate.jdbc.use_scrollable_resultset 允许Hibernate使用JDBC2的可滚动结果集. 只有在使用用户提供的JDBC连接时,这个选项才是必要的, 否则Hibernate会使用连接的元数据.

取值 true | false

hibernate.jdbc.use_streams_for_binary 在JDBC读写binary (二进制)serializable (可序列化) 的类型时使用流(stream)(系统级属性).

取值 true | false

hibernate.jdbc.use_get_generated_keys 在数据插入数据库之后,允许使用JDBC3 PreparedStatement.getGeneratedKeys() 来获取数据库生成的key(键)。需要JDBC3+驱动和JRE1.4+, 如果你的数据库驱动在使用Hibernate的标 识生成器时遇到问题,请将此值设为false. 默认情况下将使用连接的元数据来判定驱动的能力.

取值 true|false

hibernate.connection.provider_class 自定义ConnectionProvider 的类名, 此类用来向Hibernate提供JDBC连接.

取值 classname.of.ConnectionProvider

hibernate.connection.isolation 设置JDBC事务隔离级别. 查看java.sql.Connection 来了解各个值的具体意义, 但请注意多数数据库都不支持所有的隔离级别.

取值 1, 2, 4, 8

hibernate.connection.autocommit 允许被缓存的JDBC连接开启自动提交(autocommit) (不建议).

取值 true | false

hibernate.connection.release_mode 指定Hibernate在何时释放JDBC连接. 默认情况下,直到Session被显式关闭或被断开连接时,才会释放JDBC连接. 对于应用程序服务器的JTA数据源, 你应当使用after_statement , 这样在每次JDBC调用后,都会主动的释放连接. 对于非JTA的连接, 使用after_transaction 在每个事务结束时释放连接是合理的. auto 将为JTA和CMT事务策略选择after_statement , 为JDBC事务策略选择after_transaction .

取值 on_close | after_transaction | after_statement | auto

hibernate.connection.<propertyName> 将JDBC属性propertyName 传递到DriverManager.getConnection() 中去.
hibernate.jndi.<propertyName> 将属性propertyName 传递到JNDI InitialContextFactory 中去.


5、Hibernate缓存属性

属性名 用途
hibernate.cache.provider_class 自定义的CacheProvider 的类名.

取值 classname.of.CacheProvider

hibernate.cache.use_minimal_puts 以频繁的读操作为代价, 优化二级缓存来最小化写操作. 在Hibernate3中,这个设置对的集群缓存非常有用, 对集群缓存的实现而言,默认是开启的.

取值 true|false

hibernate.cache.use_query_cache 允许查询缓存, 个别查询仍然需要被设置为可缓存的.

取值 true|false

hibernate.cache.use_second_level_cache 能用来完全禁止使用二级缓存. 对那些在类的映射定义中指定<cache> 的类,会默认开启二级缓存.

取值 true|false

hibernate.cache.query_cache_factory 自定义的实现QueryCache 接口的类名, 默认为内建的StandardQueryCache .

取值 classname.of.QueryCache

hibernate.cache.region_prefix 二级缓存区域名的前缀.

取值 prefix

hibernate.cache.use_structured_entries 强制Hibernate以更人性化的格式将数据存入二级缓存.

取值 true|false


6、Hibernate事务属性

属性名 用途
hibernate.transaction.factory_class 一个TransactionFactory 的类名, 用于Hibernate Transaction API (默认为JDBCTransactionFactory ).

取值 classname.of.TransactionFactory

jta.UserTransaction 一个JNDI名字,被JTATransactionFactory 用来从应用服务器获取JTA UserTransaction .

取值 jndi/composite/name

hibernate.transaction.manager_lookup_class 一个TransactionManagerLookup 的类名 - 当使用JVM级缓存,或在JTA环境中使用hilo生成器的时候需要该类.

取值 classname.of.TransactionManagerLookup

hibernate.transaction.flush_before_completion 如果开启, session在事务完成后将被自动清洗(flush). (在Hibernate和CMT一起使用时很有用.)

取值 true | false

hibernate.transaction.auto_close_session 如果开启, session在事务完成前将被自动关闭. (在Hibernate和CMT一起使用时很有用.)

取值 true | false


7、其他属性

属性名 用途
hibernate.query.factory_class 选择HQL解析器的实现.

取值 org.hibernate.hql.ast.ASTQueryTranslatorFactory or org.hibernate.hql.classic.ClassicQueryTranslatorFactory

hibernate.query.substitutions 将Hibernate查询中的符号映射到SQL查询中的符号 (符号可能是函数名或常量名字).

取值 hqlLiteral=SQL_LITERAL, hqlFunction=SQLFUNC

hibernate.hbm2ddl.auto SessionFactory 创建时,自动将数据库schema的DDL导出到数据库. 使用 create-drop 时,在显式关闭SessionFactory 时,将drop掉数据库schema.

取值 update | create | create-drop

hibernate.cglib.use_reflection_optimizer 开启CGLIB来替代运行时反射机制(系统级属性). 反射机制有时在除错时比较有用. 注意即使关闭这个优化, Hibernate还是需要CGLIB. 你不能在hibernate.cfg.xml 中设置此属性.

取值 true | false


8、SQL方言
   Hibernate SQL方言 (hibernate.dialect )

RDBMS 方言
DB2 org.hibernate.dialect.DB2Dialect
DB2 AS/400 org.hibernate.dialect.DB2400Dialect
DB2 OS390 org.hibernate.dialect.DB2390Dialect
PostgreSQL org.hibernate.dialect.PostgreSQLDialect
MySQL org.hibernate.dialect.MySQLDialect
MySQL with InnoDB org.hibernate.dialect.MySQLInnoDBDialect
MySQL with MyISAM org.hibernate.dialect.MySQLMyISAMDialect
Oracle (any version) org.hibernate.dialect.OracleDialect
Oracle 9i/10g org.hibernate.dialect.Oracle9Dialect
Sybase org.hibernate.dialect.SybaseDialect
Sybase Anywhere org.hibernate.dialect.SybaseAnywhereDialect
Microsoft SQL Server org.hibernate.dialect.SQLServerDialect
SAP DB org.hibernate.dialect.SAPDBDialect
Informix org.hibernate.dialect.InformixDialect
HypersonicSQL org.hibernate.dialect.HSQLDialect
Ingres org.hibernate.dialect.IngresDialect
Progress org.hibernate.dialect.ProgressDialect
Mckoi SQL org.hibernate.dialect.MckoiDialect
Interbase org.hibernate.dialect.InterbaseDialect
Pointbase org.hibernate.dialect.PointbaseDialect
FrontBase org.hibernate.dialect.FrontbaseDialect
Firebird org.hibernate.dialect.FirebirdDialect


9、Hibernate日志类别

类别 功能
org.hibernate.SQL 在所有SQL DML语句被执行时为它们记录日志
org.hibernate.type 为所有JDBC参数记录日志
org.hibernate.tool.hbm2ddl 在所有SQL DDL语句执行时为它们记录日志
org.hibernate.pretty 在session清洗(flush)时,为所有与其关联的实体(最多20个)的状态记录日志
org.hibernate.cache 为所有二级缓存的活动记录日志
org.hibernate.transaction 为事务相关的活动记录日志
org.hibernate.jdbc 为所有JDBC资源的获取记录日志
org.hibernate.hql.ast 为HQL和SQL的自动状态转换和其他关于查询解析的信息记录日志
org.hibernate.secure 为JAAS认证请求做日志
org.hibernate 为任何Hibernate相关信息做日志 (信息量较大, 但对查错非常有帮助)
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics