2

我刚接到托管公司的电话,他们声称我的应用程序创建了 400 多个与 mysql 数据库的连接,并导致他们的 dbms 崩溃了!我使用 hibernate 和 c3p0 作为连接池,这是我的 hibernate 配置文件,

<?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-configuration>
  <session-factory>

    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">
            jdbc:mysql://localhost/music?characterEncoding=UTF-8
    </property>
    <property name="connection.username">USER</property>
    <property name="connection.password">PASS</property>
    <property name="show_sql">true</property>
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="current_session_context_class">thread</property>
    <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
    <property name="hbm2ddl.auto">update</property>

    <property name="hibernate.max_fetch_depth">3</property>

    <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
    <property name="hibernate.c3p0.acquire_increment">2</property>
    <property name="hibernate.c3p0.idle_test_period">300</property>
    <property name="hibernate.c3p0.timeout">1800</property>
    <property name="hibernate.c3p0.max_size">25</property>
    <property name="hibernate.c3p0.min_size" >3</property>
    <property name="hibernate.c3p0.max_statement">0</property>
    <property name="hibernate.c3p0.preferredTestQuery">select 1;</property>
    <property name="hibernate.c3p0.testConnectionOnCheckout">true</property>
    <property name="hibernate.c3p0.validate">true</property>    

    <mapping resource="com/roodakimusic/hibernate/resources/Article.hbm.xml"/>
    <mapping resource="com/roodakimusic/hibernate/resources/News.hbm.xml"/>
    <mapping resource="com/roodakimusic/hibernate/resources/Admin.hbm.xml"/>
    <mapping resource="com/roodakimusic/hibernate/resources/Maestro.hbm.xml"/>
    <mapping resource="com/roodakimusic/hibernate/resources/Roodaki.hbm.xml"/>
    <mapping resource="com/roodakimusic/hibernate/resources/Photo.hbm.xml"/>    


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

mysql和应用程序之间的任何对话都是这样的

    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();
    //session.doSomething
    session.getTransaction().commit();

我是怎么了 ?:D --edit -- 有人说它可能是 jdbc 连接器版本。

4

1 回答 1

0

为了未来!:

解决了。问题出在我的 HibernateUtil.java 中,这一行就是问题所在:

返回新的 Configuration().configure().buildSessionFactory();

于 2012-06-12T15:33:56.270 回答