我刚收到Hosting公司的电话,他们声称我的应用程序创建了超过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 - 编辑 - 有人说它可能是一个jdbc连接器版本。
答案 0 :(得分:0)
未来! :
解决。 问题出在我的HibernateUtil.java中,这就是问题所在:
返回新的Configuration()。configure()。buildSessionFactory();