-->
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.  [ 1 post ] 
Author Message
 Post subject: c3p0 problem: FYI: Wrong handling of cached prepared stmts
PostPosted: Thu May 13, 2010 11:23 am 
Beginner
Beginner

Joined: Wed Sep 06, 2006 12:08 pm
Posts: 48
Location: Warsaw - Poland - Europe - Milky Way
Hello

I would like to inform you, c3p0 users, that probably we have faced a strange behaviour of c3p0 connection pool (probably c3p0 bug).

Take care,
Adam Woźniak

Below you will find a copy+paste of the original problem report:
https://sourceforge.net/tracker/?func=d ... p_id=25357

Hai

We have noticed a strange behavior of Hibernate+c3p0.
For the following pieces of code we’ve been expecting that only one row will be inserted into CG_TAROPT_LOG table but, unfortunately, two records are inserted into our table.

Code:
package dummy;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;

import javax.persistence.EntityManager;

import org.hibernate.Session;

import pl.capgemini.tme.bonobo.common.PersistenceUtil;

public class C3P0BugReport
{
   public static void performTransaction(boolean throwAnException) throws SQLException
   {
      final EntityManager em = PersistenceUtil.createOracleEntityManager();
      PreparedStatement prepStat = null;

      try
      {
         em.getTransaction().begin();

         final Session session = (Session) em.getDelegate();

         prepStat =
            session
            .connection()
            .prepareStatement("INSERT INTO CG_TAROPT_LOG(CO_ID, ENTDATE, CS_SEQNO, DESCRIPTION) VALUES (?,?,?,?)");

         prepStat.setLong     (1, -665);
         prepStat.setTimestamp(2, new Timestamp(System.currentTimeMillis()));
         prepStat.setInt      (3, 1);
         prepStat.setString   (4, "time: " + System.currentTimeMillis());

         prepStat.addBatch();

         if(throwAnException)
            throw new NullPointerException("my exception");

         prepStat.executeBatch();

         em.getTransaction().commit();
      }
      catch(Exception e)
      {
         System.out.println("exception: " + e);
      }
      finally
      {
         if(prepStat != null)
            prepStat.close();
         PersistenceUtil.close(em);
      }      
   }

   public static void main(String[] args) throws SQLException
   {
      performTransaction(true );
      performTransaction(false);
   }
}




In hibernate.cfg.xml we have a following setting related to prepared statement cache:
<property name="hibernate.c3p0.max_statements">250</property>

In c3p0.properties config file we have a following setting related to prepared statement cache:
c3p0.maxStatementsPerConnection=100

We have found a workaround but we’ve got a feeling that this is a problem in c3p0 library.

Kind regards,
Adam Wozniak


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

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.