Java Hibernate 无法提取 ResultSet 异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23951796/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 09:21:33  来源:igfitidea点击:

Hibernate could not extract ResultSet exception

javahibernatetomcatgwt

提问by belyid

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

我已经在 Tomcat 服务器上部署了一个 GWT 应用程序。一切正常,但有时我会收到以下异常:

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:

如您所见,我使用 Hibernate 通过以下配置管理我的数据库:

<!-- 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

谢谢

采纳答案by belyid

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

js 为我指明了正确的方向,但没有解决我的问题。

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

因此,根据 js 给出的答案,我将休眠配置更改为:

<!-- 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.

主要区别在于属性“hibernate.c3p0.idle_test_period”和“hibernate.c3p0.automaticTestTable”。确保我的池中的连接仍然有效的设置,防止错误使用死连接。

回答by j.s

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

看起来连接池的配置不完整。连接超时设置为 300 秒。

<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

有关连接测试的更多信息:c3p0 连接测试

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.

如果没有这个属性,c3p0 就不会被使用。Sry,我没有看到。