hibernate.cfg.xml主要设置数据库产生连接的一些参数,生成session。
下面主要对里面的一些配置做一些说明:
数据库连接设置:
数据库驱动
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
数据库url地址
<property name="connection.url">jdbc:mysql://localhost/hibernate</property>
用户名
<property name="connection.username">root</property>
密码
<property name="connection.password">123</property>
数据库链接池的大小的设置:
<property name="connection.pool_size">1</property>
数据库方言设置:
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
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 |
Access | Access数据库的方言包:http://www.hxtt.com/test/hibernate.zip
路径:com.hxtt.support.hibernate.HxttAccessDialect |
如果是在web容器中运行hibernate,则在hibernate.cfg.xml中加入这句话:
<property name="hibernate.current_session_context_class">jta</property>
如果是在一个单独的需要进行JDBC连接的java application中运行hibernate,则这样设置:
<property name="hibernate.current_session_context_class">thread</property>
二级缓存的配置:
不使用二级缓存
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
使用二级缓存
<property name="hibernate.cache.use_query_cache">true</property>
<property name="cache.provider_class">org.hibernate.cache.EhCacheProvider</property>