-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Hibernate C3P0 Problems... Please Help
PostPosted: Fri Feb 22, 2008 8:32 am 
Newbie

Joined: Tue Sep 11, 2007 9:05 am
Posts: 13
Hi there,
I have a big problem with hibernate and MySQL and c3p0.

I am using Hibernate Entity manager and get the transactions through the factory manager like this

Code:
public class HibernateUtil {
   
    private static final EntityManagerFactory emf;
   
    static {
        try {           
            emf = Persistence.createEntityManagerFactory("AgaderPU");           
        } catch (Throwable ex) {
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }
   
    public static EntityManagerFactory getEntityManagerFactory() {
        return emf;
    }   

}


Here is my persistence.xml

Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
  <persistence-unit name="AgaderPU" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>xxx.xxx.xxx.XBean</class>
    <properties>
      <!-- use a file system based index -->
      <property name="hibernate.search.default.directory_provider" value="org.hibernate.search.store.FSDirectoryProvider"/>
      <!-- directory where the indexes will be stored -->
      <property name="hibernate.search.default.indexBase" value="/indexes"/>
      <property name="hibernate.ejb.event.post-insert" value="org.hibernate.search.event.FullTextIndexEventListener"/>
      <property name="hibernate.ejb.event.post-update" value="org.hibernate.search.event.FullTextIndexEventListener"/>
      <property name="hibernate.ejb.event.post-delete" value="org.hibernate.search.event.FullTextIndexEventListener"/>
      <property name="hibernate.connection.url" value="jdbc:mysql://boqueixon:3306/*****"/>
      <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
      <property name="hibernate.connection.password" value="****"/>
      <property name="hibernate.connection.username" value="****"/>
      <property name="hibernate.show_sql" value="true"/>
      <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
         
<property name="hibernate.c3p0.acquire_increment" value="1"/>
<property name="hibernate.c3p0.idle_test_period" value="5"/>
<property name="hibernate.c3p0.timeout" value="5"/>
<property name="hibernate.c3p0.max_size" value="5"/>
<property name="hibernate.c3p0.max_statements" value="100"/>
<property name="hibernate.c3p0.min_size" value="1"/>
<property name="hibernate.c3p0.min_pool_size" value="1"/>
<property name="hibernate.c3p0.max_pool_size" value="5"/>
    </properties>
  </persistence-unit>
</persistence>


I have configured C3P0 to just use a max of five connections for testing purposes

The problem is after i refresh 5 times my aplication hangs. It doesnt really hang it just doesnt give any error and the browser waits loading for ever. When i debug i see that the program gets the entity manager ok but as soon as a query.getResultList() is executed the breakpoint flies away and the program keeps running but without executing any statements. Its as if the program is waiting for Mysql to reply but it never does.

This depends on the number i give to hibernate.c3p0.max_size. If i give 5 then i can refresh 5 times with perfect execution but the sixth hangs and waits for ever.

The other thing is that mysql has wait_timeout = 60 seconds.
If i limit the hibernate.c3p0.timeout to 30 it doesnt seem to respond. For example i execute my program and wait for 120 seconds and hit refresh. The program executes but gives me an error that the connection is closed. Its as if hibernate keeps the mysql timedout connections

Please help


Top
 Profile  
 
 Post subject: No solution???
PostPosted: Sat Feb 23, 2008 10:28 am 
Newbie

Joined: Tue Sep 11, 2007 9:05 am
Posts: 13
Up to now, searching the forums i see that more people have been having problems with pooling and hibernate. Specifically problems with EOF exceptions caused by hibernate keeping timedout connections still in the pool. The only solution i have found is to turn off pooling by setting the hibernate pool to 0 max connections.

This doesnt seem to me as a solution.

I have a few questions.

If mysql has a max of 10 connections and a timeout of 60 seconds configured, then if we set c3p0 to 5 max connections and timeout to 30 seconds shouldnt this work???? for some reason it doesnt. As soon as hibernate gets the max connections my app seems to hang. Its as if it doesnt get rid of connections every 30 seconds? Is there maby a minimum ammount of time that hibernate needs to timeout a connection???

I have tried a similar configuration with oracle but it seems to be ok. Is this a problem concearning Mysql ?? or c3p0 or hibernate

Please people, is there any news on how to resolve this?

There cannot not be a solution to this. There must be thousands of hibernate apps that work out there.

Pleasy Hibernate forum, your my only hope


Top
 Profile  
 
 Post subject: Re: No solution???
PostPosted: Sat Feb 23, 2008 12:06 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
Give me a log or something. It looks like HB it not returning connections to the pool which might have something to do with transaction management. Do you start and commit/rollback transactions in your tests?



Farzad-


Top
 Profile  
 
 Post subject: No log
PostPosted: Sun Feb 24, 2008 1:23 pm 
Newbie

Joined: Tue Sep 11, 2007 9:05 am
Posts: 13
Hi there again. I cant post any log because there is nothing logged. I think this is because whenever hibernate gets the maximum number of connections and then tries to get another it waits indefinetly until it does. I think the problem is that i havent configured max connection age so the pool gets full and doesnt throw away any connections. And because acquireRetryAttempts and acquireRetryDelay are not set it doesnt give any error because it waits indefinetly for another connection.

I havent tried to configure all these properties yet but i will tomorrow. Hopefully by setting maxconnectionage to the timeout value of mysql and maxpoolsize to the max number of connection mysql can give everything should work fine.


Top
 Profile  
 
 Post subject: Re : Hibernate C3P0 Problems... Please Help
PostPosted: Thu Apr 10, 2008 3:24 pm 
Newbie

Joined: Thu Apr 10, 2008 3:17 pm
Posts: 3
I am stuck on the same problem. My application hangs when I use connection pool.
Do we have a solution for this issue ?

Vinay


Top
 Profile  
 
 Post subject: Re: Re : Hibernate C3P0 Problems... Please Help
PostPosted: Thu Apr 10, 2008 3:56 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
What is your configuration? What do you see in the logs?



Farzad-


Top
 Profile  
 
 Post subject: Solution
PostPosted: Fri Apr 11, 2008 3:08 am 
Newbie

Joined: Tue Sep 11, 2007 9:05 am
Posts: 13
I finnaly found out what was happening. The EOF stop occuring after i reconfigured mysql to timeout after c3p0. The Hanging was happening due to the connection not being commited or rolled back. If your app hangs it is most definetly due to this. To test set the number of max connections to 1 and check out the code when your app hangs. If there is a begin without db.commit or db.rollback thats where your problem is.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.