hibernate.cfg.xml文件的配置模板和不同数据库的配置参数

来源:互联网 发布:lnmp一键 安装php扩展 编辑:程序博客网 时间:2024/05/18 03:18


(1)hibernate.cfg.xml文件的配置模板

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE hibernate-configuration PUBLIC          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><!-- hibernate的核心配置文件 --><hibernate-configuration><session-factory><!--配置使用的mysql  --><property name="connection.driver_class">com.mysql.jdbc.Driver</property><property name="connection.username">root</property><property name="connection.password">root</property><property name="connection.url">jdbc:mysql:/127.0.0.1:3306/hibernatetest</property><!-- 配置dialect方言,明确告诉hibernate连接的是哪种数据库 --><property name="dialect">org.hibernate.dialect.MySQLDialect</property><!-- 显示出对应sql语句 --><property name="show_sql">true</property><!--让hibernate帮我们创建 一张表 --><property name="hbm2ddl.auto">update</property><pre code_snippet_id="479047" snippet_file_name="blog_20141003_1_1404018" name="code" class="html"><span style="white-space:pre"></span><!-- 指定对象映射文件 --><mapping resource="com/lc/domain/Employee.hbm.xml" />
</session-factory></hibernate-configuration>

(2)上边知识介绍了关于Oracle的配置方式 但是对于其他的很多数据库配置的url driver等等没有相关的配置;

下边就是关于目前主流数据库配置模板的详细信息:

## HypersonicSQLhibernate.dialect org.hibernate.dialect.HSQLDialecthibernate.connection.driver_class org.hsqldb.jdbcDriverhibernate.connection.username sahibernate.connection.passwordhibernate.connection.url jdbc:hsqldb:./build/db/hsqldb/hibernate#hibernate.connection.url jdbc:hsqldb:hsql://localhost#hibernate.connection.url jdbc:hsqldb:test## H2 (www.h2database.com)#hibernate.dialect org.hibernate.dialect.H2Dialect#hibernate.connection.driver_class org.h2.Driver#hibernate.connection.username sa#hibernate.connection.password#hibernate.connection.url jdbc:h2:mem:./build/db/h2/hibernate#hibernate.connection.url jdbc:h2:testdb/h2test#hibernate.connection.url jdbc:h2:mem:imdb1#hibernate.connection.url jdbc:h2:tcp://dbserv:8084/sample; #hibernate.connection.url jdbc:h2:ssl://secureserv:8085/sample; #hibernate.connection.url jdbc:h2:ssl://secureserv/testdb;cipher=AES## MySQL#hibernate.dialect org.hibernate.dialect.MySQLDialect#hibernate.dialect org.hibernate.dialect.MySQLInnoDBDialect#hibernate.dialect org.hibernate.dialect.MySQLMyISAMDialect#hibernate.connection.driver_class com.mysql.jdbc.Driver#hibernate.connection.url jdbc:mysql:///test#hibernate.connection.username gavin#hibernate.connection.password## Oracle#hibernate.dialect org.hibernate.dialect.OracleDialect#hibernate.dialect org.hibernate.dialect.Oracle9Dialect#hibernate.connection.driver_class oracle.jdbc.driver.OracleDriver#hibernate.connection.username ora#hibernate.connection.password ora#hibernate.connection.url jdbc:oracle:thin:@localhost:1521:orcl#hibernate.connection.url jdbc:oracle:thin:@localhost:1522:XE## PostgreSQL#hibernate.dialect org.hibernate.dialect.PostgreSQLDialect#hibernate.connection.driver_class org.postgresql.Driver#hibernate.connection.url jdbc:postgresql:template1#hibernate.connection.username pg#hibernate.connection.password## DB2#hibernate.dialect org.hibernate.dialect.DB2Dialect#hibernate.connection.driver_class com.ibm.db2.jcc.DB2Driver#hibernate.connection.driver_class COM.ibm.db2.jdbc.app.DB2Driver#hibernate.connection.url jdbc:db2://localhost:50000/somename#hibernate.connection.url jdbc:db2:somename#hibernate.connection.username db2#hibernate.connection.password db2## TimesTen#hibernate.dialect org.hibernate.dialect.TimesTenDialect#hibernate.connection.driver_class com.timesten.jdbc.TimesTenDriver#hibernate.connection.url jdbc:timesten:direct:test#hibernate.connection.username#hibernate.connection.password ## DB2/400#hibernate.dialect org.hibernate.dialect.DB2400Dialect#hibernate.connection.username user#hibernate.connection.password password## Native driver#hibernate.connection.driver_class COM.ibm.db2.jdbc.app.DB2Driver#hibernate.connection.url jdbc:db2://systemname## Toolbox driver#hibernate.connection.driver_class com.ibm.as400.access.AS400JDBCDriver#hibernate.connection.url jdbc:as400://systemname## Derby (not supported!)#hibernate.dialect org.hibernate.dialect.DerbyDialect#hibernate.connection.driver_class org.apache.derby.jdbc.EmbeddedDriver#hibernate.connection.username#hibernate.connection.password#hibernate.connection.url jdbc:derby:build/db/derby/hibernate;create=true## Sybase#hibernate.dialect org.hibernate.dialect.SybaseDialect#hibernate.connection.driver_class com.sybase.jdbc2.jdbc.SybDriver#hibernate.connection.username sa#hibernate.connection.password sasasa#hibernate.connection.url jdbc:sybase:Tds:co3061835-a:5000/tempdb## SAP DB#hibernate.dialect org.hibernate.dialect.SAPDBDialect#hibernate.connection.driver_class com.sap.dbtech.jdbc.DriverSapDB#hibernate.connection.url jdbc:sapdb://localhost/TST#hibernate.connection.username TEST#hibernate.connection.password TEST#hibernate.query.substitutions yes 'Y', no 'N'## MS SQL Server#hibernate.dialect org.hibernate.dialect.SQLServerDialect#hibernate.connection.username sa#hibernate.connection.password sa## JSQL Driver#hibernate.connection.driver_class com.jnetdirect.jsql.JSQLDriver#hibernate.connection.url jdbc:JSQLConnect://1E1/test## JTURBO Driver#hibernate.connection.driver_class com.newatlanta.jturbo.driver.Driver#hibernate.connection.url jdbc:JTurbo://1E1:1433/test

(3)C3P0 连接池

############################## C3P0 Connection Pool###############################hibernate.c3p0.max_size 2#hibernate.c3p0.min_size 2#hibernate.c3p0.timeout 5000#hibernate.c3p0.max_statements 100#hibernate.c3p0.idle_test_period 3000#hibernate.c3p0.acquire_increment 2#hibernate.c3p0.validate false

(4)Proxool 连接池

################################# Proxool Connection Pool################################### Properties for external configuration of Proxoolhibernate.proxool.pool_alias pool1## Only need one of the following#hibernate.proxool.existing_pool true#hibernate.proxool.xml proxool.xml#hibernate.proxool.properties proxool.properties

(5)JDBC Settings

######################## JDBC Settings ########################## specify a JDBC isolation level#hibernate.connection.isolation 4## enable JDBC autocommit (not recommended!)#hibernate.connection.autocommit true## set the JDBC fetch size#hibernate.jdbc.fetch_size 25## set the maximum JDBC 2 batch size (a nonzero value enables batching)#hibernate.jdbc.batch_size 5#hibernate.jdbc.batch_size 0## enable batch updates even for versioned datahibernate.jdbc.batch_versioned_data true## enable use of JDBC 2 scrollable ResultSets (specifying a Dialect will cause Hibernate to use a sensible default)#hibernate.jdbc.use_scrollable_resultset true## use streams when writing binary types to / from JDBChibernate.jdbc.use_streams_for_binary true## use JDBC 3 PreparedStatement.getGeneratedKeys() to get the identifier of an inserted row#hibernate.jdbc.use_get_generated_keys false## choose a custom JDBC batcher# hibernate.jdbc.factory_class## enable JDBC result set column alias caching ## (minor performance enhancement for broken JDBC drivers)# hibernate.jdbc.wrap_result_sets## choose a custom SQL exception converter#hibernate.jdbc.sql_exception_converter

(6)Second-level Cache(二级缓存)

############################# Second-level Cache ############################### optimize chache for minimal "puts" instead of minimal "gets" (good for clustered cache)#hibernate.cache.use_minimal_puts true## set a prefix for cache region nameshibernate.cache.region_prefix hibernate.test## disable the second-level cache#hibernate.cache.use_second_level_cache false## enable the query cache#hibernate.cache.use_query_cache true## store the second-level cache entries in a more human-friendly format#hibernate.cache.use_structured_entries true## choose a cache implementation#hibernate.cache.provider_class org.hibernate.cache.EhCacheProvider#hibernate.cache.provider_class org.hibernate.cache.EmptyCacheProviderhibernate.cache.provider_class org.hibernate.cache.HashtableCacheProvider#hibernate.cache.provider_class org.hibernate.cache.TreeCacheProvider#hibernate.cache.provider_class org.hibernate.cache.OSCacheProvider#hibernate.cache.provider_class org.hibernate.cache.SwarmCacheProvider## choose a custom query cache implementation#hibernate.cache.query_cache_factory


这里只是一些常见的配置 如何详细的配置信息请 查找:hibernate-distribution-3.3.1.GA---->project---->etc---->hibernate.properties文件!


如果没有这个文件的话 请回复你们的邮箱 发给你们!


注:转载请注明出处!!


4 0