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=25357Hai
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