Hibernate3的配置参数汇总
Hibernate3的配置参数汇总SQL 方言1、Hibernate JDBC属性hibernate.connection.driver_class jdbc 驱动类hibernate.con
Hibernate3的配置参数汇总
SQL 方言
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 样例代码:
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 样例代码:
,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意味着将关闭默认的外连接抓取. 取值 建议在0到3之间取值
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的批量更新. 取值 建议取5到30之间的值
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.
将JDBC 属性propertyName 传递到DriverManager.getConnection()中去.
hibernate.jndi.
将属性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
能用来完全禁止使用二级缓存. 对那些在类的映射定义中指定
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 方言
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 相关信息做日志 (信息量较大, 但对查错非常有帮助)