hibernate.cfg.xml以及C3P0连接池的配置
1.MySql数据库的配置:
<hibernate-configuration> <session-factory> <property name="show_sql">true</property> //显示SQL语句 <property name="current_session_context_class">thread</property> //实用CurrentSession <!-- 配置数据库的连接属性 --> <property name="myeclipse.connection.profile">MySQL5.0</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="connection.url"> jdbc:mysql://localhost:3306/crm?useUnicode=true&characterEncoding=gb2312 </property> <property name="connection.username">root</property> <property name="connection.password">root</property> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="show_sql">true</property> <!-- 配置C3P0连接池属性 --> <property name="hibernate.connection.provider_class"> org.hibernate.connection.C3P0ConnectionProvider //此句必须加,很重要 </property> <property name="hibernate.c3p0.min_size">5</property> <property name="hibernate.c3p0.max_size">20</property> <property name="hibernate.c3p0.timeout">50000</property> <property name="hibernate.c3p0.max_statements">100</property> <property name="hibernate.c3p0.idle_test_period">3000</property> <property name="hibernate.c3p0.acquire_increment">2</property> //当连接池耗尽并接到获得连接的请求,则新增加连接的数量 <property name="hibernate.c3p0.validate">false</property> //是否验证,检查连接 <property name="hibernate.connection.SetBigStringTryClob">true</property> //?? <property name="preferredTestQuery">select 1 from dual</property> <!-- 其他配置 --> <property name="jdbc.use_scrollable_resultset">true</property> //是否允许Hibernate用JDBC的可滚动的结果集。对分页的结果集。对分页时的设置非常有帮助。 <property name="Connection.useUnicode">true</property> //连接数据库时是否使用Unicode编码 <!-- 配置持久化映射文件 --> <mapping resource="com/ORM/City.hbm.xml" /> <mapping resource="com/ORM/Client.hbm.xml" /> <mapping resource="com/ORM/Province.hbm.xml" /> </session-factory> </hibernate-configuration>
2.Oracle数据库的配置:
<hibernate-configuration> <session-factory> <property name="show_sql">true</property> <property name="current_session_context_class">thread</property> <!-- 配置数据库的连接属性 --> <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property> <property name="connection.driver_class">oracle.jdbc.OracleDriver</property> <property name="connection.url">jdbc:oracle:thin:@localhost:1521:orcl</property> <property name="connection.username">user</property> <property name="connection.password">111111</property> <!-- 配置C3P0连接池属性 --> <property name="hibernate.connection.provider_class"> org.hibernate.connection.C3P0ConnectionProvider </property> <property name="hibernate.c3p0.min_size">5</property> <property name="hibernate.c3p0.max_size">20</property> <property name="hibernate.c3p0.timeout">1800</property> <property name="hibernate.c3p0.max_statements">50</property> <property name="hibernate.c3p0.acquire_increment">2</property> <property name="hibernate.connection.SetBigStringTryClob">true</property> //?? <property name="preferredTestQuery">select 1 from dual</property> //用来配置测试连接的一种方式 <!-- 提高性能的配置 --> <property name="jdbc.fetch_size">50</property> //读:每次从数据库中取出的记录条数。 <property name="jdbc.batch_size">0</property> //写:批量删除、批量更新和批量插入的时候的批次大小 <!-- 其他配置 --> <property name="jdbc.use_scrollable_resultset">true</property> //是否允许Hibernate用JDBC的可滚动的结果集。对分页的结果集。对分页时的设置非常有帮助。 <property name="Connection.useUnicode">true</property> //连接数据库时是否使用Unicode编码 <!-- 配置持久化映射文件 --> <mapping resource="com/huaxia/entity/User.hbm.xml"/> </session-factory> </hibernate-configuration>
相关:
hibernate的速度问题--hibernate.jdbc.fetch_size和 hibernate.jdbc.batch_size
DBCP、C3P0、Proxool 、 BoneCP开源连接池的比较
相关推荐
hibernate.cfg.xml hibernate框架的配置文件
(hibernate调用C3p0)hibernate.cfg.xml
由于spring对hibernate配置文件hibernate.cfg.xml的集成相当好,可以在项目中放弃hibernate.cfg.xml文件,介绍mappingLocations、mappingDirectoryLocations与mappingJarLocations的用法和区别
Hibernate配置文件hibernate.cfg.xml中配置信息详解!
这是Hibernate的配置文件,hibernate.cfg.xml的具体写法,共友友们参考~~谢谢~
hibernate.cfg.xml文件详细解释收集的一个比较好的hibernate.cfg.xml文件解释
Hibernate.cfg.xml配置总结
hibernate配置文件hibernate.cfg.xml的详细解释
高级Hibernate4开发技术:ORM思想,hibernate介绍,hibernate.cfg.xml配置,hbm.xml映射文件详解,主键生成策略使用,PO对象状态及状态的转换分析、一级缓存,Hibernate数据检索技术,Hibernate高级映射技术,...
高级Hibernate4开发技术:ORM思想,hibernate介绍,hibernate.cfg.xml配置,hbm.xml映射文件详解,主键生成策略使用,PO对象状态及状态的转换分析、一级缓存,Hibernate数据检索技术,Hibernate高级映射技术,...
Hibernate4的全套jar包,及hbm.xml(模板)+hibernate.cfg.xml(模板)+c3p0(全套)+ojdbc14.jar
hibernate.cfg.xml中各节点的所有属性值,取自hibernate官网,纯天然无污染。原装!
JavaEE spring和Hibernate整合(有hibernate.cfg.xml)