Hi Sirs, I am completing a SE Java application. I included this method in my hibernate Util class to be able to use a connection for my reports, or specific stored procedures calls. public static Connection getConnection() { if (connection == null) { try(Session session = getSessionFactory().openSession()) { session.beginTransaction(); connection = session.doReturningWork((Connection cnctn) -> { return cnctn; }); session.getTransaction().commit(); } catch (HibernateException e) { MyExceptionUtil.handle(null, e); return null; } } return connection; } This works well when using the built-in connection pool, and fails when switching to C3P0. I tracked down the issue by checking if the connection returned was closed. What is strange is the cnctn.isClosed comes false, while the test connection.isClosed comes true. What makes it change state?
Here is my configuration <property name="hibernate.c3p0.acquireIncrement">3</property> <property name="hibernate.c3p0.maxIdleTime">0</property> <property name="hibernate.c3p0.initialisePoolSize">3</property> <property name="hibernate.c3p0.minPoolSize">3</property> <property name="hibernate.c3p0.maxPoolSize">5</property> <property name="hibernate.c3p0.maxStatements">100</property> <property name="hibernate.c3p0.maxStatementsPerConnection">20</property>
Thanks in advance for your help.
|