Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java MySQL连接在Hibernate应用程序中的操作之间关闭_Java_Mysql_Hibernate - Fatal编程技术网

Java MySQL连接在Hibernate应用程序中的操作之间关闭

Java MySQL连接在Hibernate应用程序中的操作之间关闭,java,mysql,hibernate,Java,Mysql,Hibernate,我在Apache tomcat上安装的应用程序成功运行,然后我们安装了用于安装Bugzilla的新Apache,Bugzilla成功安装并运行,我的Apache tomcat在端口1891上运行,Apache for Bugzilla在端口80上运行,当两者同时运行时,安装在tomcat上的应用程序将停止工作 我的应用程序执行两个操作 1.插入 2.基于第1点的一些其他重型操作 当请求插入时,我的应用程序表现良好并执行插入,但无法执行2操作,并出现以下异常: Hibernate: sel

我在Apache tomcat上安装的应用程序成功运行,然后我们安装了用于安装Bugzilla的新Apache,Bugzilla成功安装并运行,我的Apache tomcat在端口1891上运行,Apache for Bugzilla在端口80上运行,当两者同时运行时,安装在tomcat上的应用程序将停止工作

我的应用程序执行两个操作 1.插入 2.基于第1点的一些其他重型操作

当请求插入时,我的应用程序表现良好并执行插入,但无法执行2操作,并出现以下异常:

    Hibernate: select vendor0_.vendor_coupon_id as vendor1_, vendor0_.name as name1_, vendor0_.heading as heading1_, vendor0_.artwork1 as artwork4_1_, vendor0_.artwork2 as artwork5_1_, vendor0_.redeem_doc as redeem6_1_, vendor0_.icon as icon1_, vendor0_.pkg_name as pkg8_1_, vendor0_.apk as apk1_, vendor0_.country as country1_, vendor0_.description as descrip11_1_ from vendor vendor0_ where vendor0_.country=?
org.hibernate.exception.GenericJDBCException: could not execute query
    at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
    at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    at org.hibernate.loader.Loader.doList(Loader.java:1565)
    at org.hibernate.loader.Loader.list(Loader.java:1545)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:840)
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
    at com.learning.controller.VendorCRUD.getVendorsForCountry(VendorCRUD.java:137)
    at com.avilyne.rest.resource.CouponBinding.UpdateCoupon(CouponBinding.java:50)
    at com.avilyne.rest.resource.CouponBinding.run(CouponBinding.java:44)
    at java.lang.Thread.run(Thread.java:724)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    at com.mysql.jdbc.Util.getInstance(Util.java:386)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1014)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919)
    at com.mysql.jdbc.ConnectionImpl.throwConnectionClosedException(ConnectionImpl.java:1269)
    at com.mysql.jdbc.ConnectionImpl.checkClosed(ConnectionImpl.java:1261)
    at com.mysql.jdbc.ConnectionImpl.prepareStatement(ConnectionImpl.java:4246)
    at com.mysql.jdbc.ConnectionImpl.prepareStatement(ConnectionImpl.java:4212)
    at sun.reflect.GeneratedMethodAccessor65.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.mchange.v2.c3p0.stmt.GooGooStatementCache$1StmtAcquireTask.run(GooGooStatementCache.java:525)
    at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 75,824,749 milliseconds ago.  The last packet sent successfully to the server was 75,824,749 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1117)
    at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3829)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2449)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2629)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2719)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2318)
    at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
    at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:118)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:1239)
    at org.hibernate.loader.Loader.doQuery(Loader.java:374)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:210)
    at org.hibernate.loader.Loader.doList(Loader.java:1562)
    at org.hibernate.loader.Loader.list(Loader.java:1545)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:840)
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
    at com.learning.controller.VendorCRUD.getVendorById(VendorCRUD.java:153)
    at com.avilyne.rest.resource.VendorOffers.getOffers(VendorOffers.java:69)
    at sun.reflect.GeneratedMethodAccessor84.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
    at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)
    at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
    at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1483)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1414)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1363)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1353)
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:414)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:947)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)
Caused by: java.net.SocketException: Broken pipe
    at java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
    at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
    at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
    at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3810)
    ... 53 more
以下是我的Hibernate配置文件:

 <?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD     `3//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">` 
<hibernate-configuration> 
<session-factory> 
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> 
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/offers?autoReconnect=true</property> 
<property name="hibernate.connection.username">root</property> 
<property name="show_sql">true</property> 
<property name="connection.password">password</property> 
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.jdbc.batch_size">20</property>
<property name="hibernate.cache.use_second_level_cache">false</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> 
<property name="hbm2ddl.auto">update</property>
<property name="dynamic-update">true</property>
<mapping resource="person.hbm.xml"/>
<mapping resource="vendor.hbm.xml"/>
<mapping resource="coupons.hbm.xml"/>
<mapping resource="binding.hbm.xml"/>
<mapping resource="mperson.hbm.xml"/>
</session-factory> 
</hibernate-configuration>

` 
com.mysql.jdbc.Driver
jdbc:mysql://localhost:3306/offers?autoReconnect=true 
根
真的
密码
5.
20
300
3000
50
20
假的
org.hibernate.dialogue.mysqldialogue
更新
真的
当我们停止安装bugzilla的Apache时,我安装在tomcat上的应用程序运行良好

查看日志,在我看来,在insert操作之后,数据库连接被关闭,因此没有执行第二个操作。我不知道连接是如何关闭的?
我忘记添加这两个服务器(安装了bugzilla的Apache和安装了应用程序的Tomcat)使用相同的mysql服务器,并且每台this都运行在具有4 Gb ram和i5的ubuntu机器上。

我猜没有足够的连接来满足tomcat和bugzilla应用程序的需要。如果足够的连接很重要,那么为什么我的应用程序会受到影响,据我所知,如果连接数较少,cp03将自动增加3个连接数。我猜MySQL服务器本身没有足够的可用连接。您的池可能需要任意多的连接,但是如果MySQL被配置为只允许5个,您将不能拥有超过5个。