休眠连接池 [英] hibernate connection pool

查看:117
本文介绍了休眠连接池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  12:30:35,038 INFO DriverManagerConnectionProvider:64  - 使用Hibernate内置连接池(不适合生产使用!)
12:30:35,038信息DriverManagerConnectionProvider:65 - Hibernate连接池大小:20

Hibernate Config:

 < hibernate-configuration> 
< session-factory>
< property name =hibernate.connection.driver_class> com.mysql.jdbc.Driver< / property>
< property name =hibernate.connection.url> jdbc:mysql:// localhost:3306 / xxx?autoReconnect = true< / property>
< property name =hibernate.connection.username>根< / property>
< property name =hibernate.connection.password> xxxx< / property>
< property name =show_sql> false< / property>
< property name =dialect> org.hibernate.dialect.MySQLDialect< / property>
< property name =hibernate.hbm2ddl.auto>更新< / property>
< property name =hibernate.c3p0.min_size> 5< / property>
< property name =hibernate.c3p0.max_size> 200< / property>
< property name =hibernate.c3p0.max_statements> 200< / property>
< property name =current_session_context_class>线程< / property>
< / session-factory>
< / hibernate-configuration>


解决方案

 < !DOCTYPE hibernate-configuration PUBLIC 
- // Hibernate / Hibernate配置DTD 3.0 // EN
http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd\">
< hibernate-configuration>
< session-factory>

<! - datasource config - >
< property name =connection.url> jdbc:mysql:// localhost:3306 / db?useUnicode = true& amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp;
< property name =hibernate.dialect> org.hibernate.dialect.MySQL5InnoDBDialect< / property>
< property name =connection.driver_class> com.mysql.jdbc.Driver< / property>

< property name =connection.username> user< / property>
< property name =connection.password> pass< / property>

<! - c3p0 config http://www.hibernate.org/214.html - >
< property name =connection.provider_class> org.hibernate.connection.C3P0ConnectionProvider< / property>
< property name =hibernate.c3p0.acquire_increment> 1< / property>
< property name =hibernate.c3p0.idle_test_period> 60< / property>
< property name =hibernate.c3p0.min_size> 1< / property>
< property name =hibernate.c3p0.max_size> 2< / property>
< property name =hibernate.c3p0.max_statements> 50< / property>
< property name =hibernate.c3p0.timeout> 0< / property>
< property name =hibernate.c3p0.acquireRetryAttempts> 1< / property>
< property name =hibernate.c3p0.acquireRetryDelay> 250< / property>

< property name =hibernate.show_sql> true< / property>
< property name =hibernate.use_sql_comments> true< / property>

< property name =hibernate.transaction.factory_class> org.hibernate.transaction.JDBCTransactionFactory< / property>
< property name =hibernate.current_session_context_class>线程< / property>

...

< / session-factory>
< / hibernate-configuration>


I can't seem to get hibernate to use c3p0 for connection pooling, it says

12:30:35,038  INFO DriverManagerConnectionProvider:64 - Using Hibernate built-in connection pool (not for production use!)
12:30:35,038  INFO DriverManagerConnectionProvider:65 - Hibernate connection pool size: 20

Hibernate Config:

<hibernate-configuration>
  <session-factory>
      <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
      <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/xxx?autoReconnect=true</property>
      <property name="hibernate.connection.username">root</property>
      <property name="hibernate.connection.password">xxxx</property>
      <property name="show_sql">false</property>
      <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
      <property name="hibernate.hbm2ddl.auto">update</property>
      <property name="hibernate.c3p0.min_size">5</property>
      <property name="hibernate.c3p0.max_size">200</property>
      <property name="hibernate.c3p0.max_statements">200</property>
      <property name="current_session_context_class">thread</property>
  </session-factory>
</hibernate-configuration>

解决方案

<!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>

        <!-- datasource config -->
        <property name="connection.url">jdbc:mysql://localhost:3306/db?useUnicode=true&amp;characterEncoding=UTF-8&amp;autoReconnect=true</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>

        <property name="connection.username">user</property>
        <property name="connection.password">pass</property>

        <!-- c3p0 config http://www.hibernate.org/214.html -->
        <property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>        
        <property name="hibernate.c3p0.acquire_increment">1</property>
        <property name="hibernate.c3p0.idle_test_period">60</property>
        <property name="hibernate.c3p0.min_size">1</property>
        <property name="hibernate.c3p0.max_size">2</property>
        <property name="hibernate.c3p0.max_statements">50</property>
        <property name="hibernate.c3p0.timeout">0</property>
        <property name="hibernate.c3p0.acquireRetryAttempts">1</property>
        <property name="hibernate.c3p0.acquireRetryDelay">250</property>

        <property name="hibernate.show_sql">true</property>
        <property name="hibernate.use_sql_comments">true</property>

        <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
        <property name="hibernate.current_session_context_class">thread</property>

        ...

    </session-factory>
</hibernate-configuration>

这篇关于休眠连接池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆