Hibernate could not extract ResultSet exception

67,357

Solution 1

j.s pointed me in the right direction but didn't solve my problem.

So based on the answer given by j.s I changed my hibernate configuration to:

<!-- Database connection settings -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>

        <property name="connection.url">jdbc:mysql://server:3306/db?autoReconnect=true</property>
        <property name="connection.username">user</property>        
        <property name="connection.password">password</property>

        <!-- C3P0 connection pool -->
        <property name="hibernate.c3p0.timeout">600</property>
        <property name="hibernate.c3p0.maxIdleTimeExcessConnections">20</property>

        <!--  Connection testing settings -->
        <property name="hibernate.c3p0.validate">false</property>
        <property name="hibernate.c3p0.idle_test_period">30</property>
        <property name="hibernate.c3p0.automaticTestTable">conTestTable</property>

        <!-- SQL dialect -->
        <property name="dialect">com.ohapp.webtattoon.server.service.Mysql5BitBooleanDialect</property>

        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>

        <!-- Disable the second-level cache -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">false</property>

        <!-- Drop and re-create the database schema on startup -->
        <property name="hbm2ddl.auto">validate</property>

The key difference is the properties "hibernate.c3p0.idle_test_period" and "hibernate.c3p0.automaticTestTable". A setup that ensures that the connections in my pool are still valid preventing errors from using dead connections.

Solution 2

Looks like the configuration of the connection pool is incomplete. The timeout of connections is set to 300s.

<property name="hibernate.c3p0.timeout">300</property>

Therefore a connection can become invalid. These invalid connections are not discarded from the connection pool until you specify a rule about what to do with these connections.

By adding the following line, a connection test is performed at every connection checkout to verify that the connection is valid:

 <property name="hibernate.c3p0.testConnectionOnCheckout" value="true" />

More info about connection testing: c3p0 connection testing

Edit: There is another very important property, which is not present in your config:

<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>

Without this property c3p0 is not used at all. Sry, that i didn't see that.

Share:
67,357
belyid
Author by

belyid

After a degree in management realized that it's more difficult to get the actual information than process it. So here I am learning better ways to reach the information. Acquainted with: Javascript Java C# Visual Basic HTML SQL I currently use the following frameworks: Node.js AngularJS

Updated on August 01, 2020

Comments

  • belyid
    belyid almost 4 years

    I've deployed an GWT application on a Tomcat server. Everything is working fine but sometimes I get the following exception:

    org.hibernate.exception.JDBCConnectionException: could not extract ResultSet
            at com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:389)
            at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:579)
            at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:265)
            at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:305)
            at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:301)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
            at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
            at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
            at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:74)
            at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
            at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
            at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
            at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1017)
            at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:652)
            at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
            at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1575)
            at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1533)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
            at java.lang.Thread.run(Thread.java:744)
    Caused by: org.hibernate.exception.JDBCConnectionException: could not extract ResultSet
            at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:132)
            at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
            at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
            at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
            at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:61)
            at org.hibernate.loader.Loader.getResultSet(Loader.java:2040)
            at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1837)
            at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1816)
            at org.hibernate.loader.Loader.doQuery(Loader.java:900)
            at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:342)
            at org.hibernate.loader.Loader.doList(Loader.java:2526)
            at org.hibernate.loader.Loader.doList(Loader.java:2512)
    

    As you can see I use Hibernate to manage my database with the following configuration:

    <!-- Database connection settings -->
            <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
    
            <property name="connection.url">jdbc:mysql://server:3306/db</property>
            <property name="connection.username">username</property>
    
            <property name="connection.password">password</property>
    
            <!-- JDBC connection pool (use the built-in) -->
            <property name="hibernate.c3p0.min_size">1</property>
            <property name="hibernate.c3p0.max_size">15</property>
            <property name="hibernate.c3p0.timeout">300</property>
            <property name="hibernate.c3p0.max_statements">50</property>
            <property name="hibernate.c3p0.idle_test_period">3000</property>
    
            <!-- SQL dialect -->
            <property name="dialect">com.ohapp.webtattoon.server.service.Mysql5BitBooleanDialect</property>
    
            <!-- Enable Hibernate's automatic session context management -->
            <property name="current_session_context_class">thread</property>
    
            <!-- Disable the second-level cache -->
            <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
    
            <!-- Echo all executed SQL to stdout -->
            <property name="show_sql">false</property>
    
            <!-- Drop and re-create the database schema on startup -->
            <property name="hbm2ddl.auto">validate</property>
    

    I don't have a clue why this happens. I would really appreciate some help.

    Thank you