Estou utilizando o C3p0 ou (C3po) para fazer Pool de conexões no Hibernate…
meu arquivo hibernate.cgf esta configurado desta maneira:
...
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.password">sgc</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@10.74.10.241:1521:XE</property>
<property name="hibernate.connection.username">sgc</property>
<property name="hibernate.default_schema">SGC</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.jdbc.batch_size">20</property>
<property name="hibernate.use_sql_comments">true</property>
<property name="hibernate.query.substitutions">true</property>
<!-- Condiguração do c3p0 -->
<property name="hibernate.c3p0.max_size">10</property>
<property name="hibernate.c3p0.min_size">2</property>
<property name="hibernate.c3p0.timeout">50000</property>
<property name="hibernate.c3p0.max_statements">10</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="hibernate.c3p0.acquire_increment">2</property>
...
Entretanto toda vez que eu faço alguma operação de Incluir, Alterar ou Excluir o C3p0 retorna o seguinte erro:
18:19:10,604 INFO [GooGooStatementCache] Problem with checked-in Statement, discarding.
java.lang.NullPointerException
at oracle.jdbc.dbaccess.DBData.clearItem(DBData.java:306)
at oracle.jdbc.dbaccess.DBDataSetImpl.clearItem(DBDataSetImpl.java:2481)
at oracle.jdbc.driver.OraclePreparedStatement.clearParameters(OraclePreparedStatement.java:3290)
at com.mchange.v2.c3p0.stmt.GooGooStatementCache.refreshStatement(GooGooStatementCache.java:522)
at com.mchange.v2.c3p0.stmt.GooGooStatementCache.checkinStatement(GooGooStatementCache.java:136)
at com.mchange.v2.c3p0.impl.NewPooledConnection.checkinStatement(NewPooledConnection.java:191)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.close(NewProxyPreparedStatement.java:1807)
at org.hibernate.jdbc.AbstractBatcher.closePreparedStatement(AbstractBatcher.java:526)
at org.hibernate.jdbc.AbstractBatcher.closeStatement(AbstractBatcher.java:265)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:245)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at br.com.brt.correspondencia.dao.hibernate.HibernateDAO.insert(HibernateDAO.java:224)
at br.com.brt.correspondencia.ejb.empresa.EmpresaBean.incluirHistoricoEmpresa(EmpresaBean.java:150)
at Empresa_StatelessSessionBeanWrapper42.incluirHistoricoEmpresa(Empresa_StatelessSessionBeanWrapper42.java:906)
at br.com.brt.correspondencia.bd.empresa.EmpresaBD.incluirHistoricoEmpresa(EmpresaBD.java:40)
at br.com.brt.correspondencia.action.empresa.EmpresaIncluirSalvarAction.execute(EmpresaIncluirSalvarAction.java:60)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)
at br.com.brt.correspondencia.security.util.SecurityFilter.doFilter(SecurityFilter.java:54)
at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:604)
at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:317)
at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:790)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:186)
at java.lang.Thread.run(Thread.java:534)
Eu suspeito que é algo errado que eu fiz na minha classe HibernateUtil:
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static SessionFactory factory;
static {
//Bloco estático que inicializa o Hibernate
try {
factory = new Configuration().configure("/br/com/brt/correspondencia/dao/hibernate/hibernate.cfg.xml").buildSessionFactory();
} catch (Exception e) {
e.printStackTrace();
factory = null;
}
}
public static Session getSession() {
//Retorna a sessão aberta
return factory.openSession();
}
}
Independente do erro, ela faz as operações, mas suspeito que isso possa me gerar dor de cabeça no futuro.
Sugestões???..