2

i just got a call from Hosting company, they claimed that my application creates over 400 connections to mysql database and cause their dbms to crash some how! i am using hibernate and c3p0 as a connection pool, here is my hibernate configuration file,

<?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>

and any dialog between mysql and application are like this

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

what is wrong with me ? :D --edit -- some say that it could be a jdbc connectors version.

MoienGK
  • 4,544
  • 11
  • 58
  • 92
  • c3p0 configuration is inside hibernate configuration. isnt it? – MoienGK Jun 11 '12 at 12:58
  • http://stackoverflow.com/questions/3768263/how-can-i-prevent-hibernate-c3p0-mysql-creating-large-numbers-of-sleeping-co?rq=1 – rkosegi Jun 11 '12 at 13:00
  • @rkosegi , my situation is bit different, the conversation there is about building session or getting the existing one – MoienGK Jun 11 '12 at 13:14

1 Answers1

0

for future! :

SOLVED. the problem was in my HibernateUtil.java , this line was the problem :

return new Configuration().configure().buildSessionFactory();

MoienGK
  • 4,544
  • 11
  • 58
  • 92
  • What is the problem and how did you fix it ? – AndroidDev Apr 06 '17 at 20:42
  • @AndroidDev It was centuries ago :)) . The line that I have mentioned was creating a new session factory every time. It was a problem with hibernate configuration – MoienGK Apr 10 '17 at 11:46