-->
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: Get a connection from Hibernate via C3P0 Pooling
PostPosted: Mon Jun 20, 2016 10:45 am 
Newbie

Joined: Mon May 16, 2016 12:13 pm
Posts: 1
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.


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.