2017-08-29 65 views
1

我们有一个应用程序在使用mysql的tomcat上运行。最近,我们升级了休眠4.1.7。时不时,非常间歇地,我得到通信链接失败。Hibernate 4.1.x抛出异常 - 通信链接失败

org.hibernate.exception.JDBCConnectionException: Communications link failure 

Last packet sent to the server was 15667584 ms ago. 


at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:131) ~[hibernate-core-4.1.7.Final.jar:4.1.7.Final] 
     at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49) ~[hibernate-core-4.1.7.Final.jar:4.1.7.Final] 
     at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125) ~[hibernate-core-4.1.7.Final.jar:4.1.7.Final] 
     at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110) ~[hibernate-core-4.1.7.Final.jar:4.1.7.Final] 
     at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129) ~[hibernate-core-4.1.7.Final.jar:4.1.7.Final] 
     at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81) ~[hibernate-core-4.1.7.Final.jar:4.1.7.Final] 
     at com.sun.proxy.$Proxy49.executeUpdate(Unknown Source) ~[?:?] 
     at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:96) ~[hibernate-core-4.1.7.Final.jar:4.1.7.Final] 
     at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:58) ~[hibernate-core-4.1.7.Final.jar:4.1.7.Final] 
     at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2870) ~[hibernate-core-4.1.7.Final.jar:4.1.7.Final] 
     at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3381) ~[hibernate-core-4.1.7.Final.jar:4.1.7.Final] 
     at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:81) ~[hibernate-core-4.1.7.Final.jar:4.1.7.Final] 
     at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362) ~[hibernate-core-4.1.7.Final.jar:4.1.7.Final] 
     at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:203) ~[hibernate-core-4.1.7.Final.jar:4.1.7.Final] 
     at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:183) ~[hibernate-core-4.1.7.Final.jar:4.1.7.Final] 
     at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:167) ~[hibernate-core-4.1.7.Final.jar:4.1.7.Final] 
     at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:320) ~[hibernate-core-4.1.7.Final.jar:4.1.7.Final] 
     at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:287) ~[hibernate-core-4.1.7.Final.jar:4.1.7.Final] 
     at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:193) ~[hibernate-core-4.1.7.Final.jar:4.1.7.Final] 
     at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:126) ~[hibernate-core-4.1.7.Final.jar:4.1.7.Final] 
     at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:204) ~[hibernate-core-4.1.7.Final.jar:4.1.7.Final] 
     at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55) ~[hibernate-core-4.1.7.Final.jar:4.1.7.Final] 
     at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:189) ~[hibernate-core-4.1.7.Final.jar:4.1.7.Final] 
     at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49) ~[hibernate-core-4.1.7.Final.jar:4.1.7.Final] 
     at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90) ~[hibernate-core-4.1.7.Final.jar:4.1.7.Final] 
     at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:753) ~[hibernate-core-4.1.7.Final.jar:4.1.7.Final] 
     at org.hibernate.internal.SessionImpl.save(SessionImpl.java:745) ~[hibernate-core-4.1.7.Final.jar:4.1.7.Final] 
     at org.hibernate.internal.SessionImpl.save(SessionImpl.java:741) ~[hibernate-core-4.1.7.Final.jar:4.1.7.Final] 
     at common.HibernateUtil.saveObjectNonTransactional(HibernateUtil.java:123) ~[classes/:?] 

我们看了一下mysql的一面,确认我们有足够的可用连接。这是部分休眠配置

<!--property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property--> 
    <property name="dialect">org.hibernate.dialect.MySQL5Dialect</property> 

    <!--c3p0 connection pool - can be used for deployment and schema generation --> 

    <property name="connection.url">jdbc:mysql://10.222.8.60:3306/pasi_v1_5</property> 
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property> 

    <property name="connection.username">username</property> 
    <property name="connection.password">password</property> 
    <property name="hibernate.c3p0.min_size">3</property> 
    <property name="hibernate.c3p0.max_size">10</property> 
    <property name="hibernate.c3p0.timeout">7200</property> 
    <property name="hibernate.c3p0.max_statements">50</property> 
    <property name="hibernate.c3p0.idle_test_period">1800</property> 
    <property name="hibernate.show_sql">false</property> 
    <!--<property name="hibernate.c3p0.validate">true</property>!--> 

任何帮助将不胜感激

+0

什么是max c3p0最大池大小和mysql超时? – Amogh

+0

MySQL有一个'wait_timeout'设置,它会在一段时间内关闭连接空闲。如果您的'idle_test_period'和'timeout'大于MySQL'wait_timeout'(默认为28800秒),那么未使用的连接将有机会在被C3p0测试或超时之前由MySQL服务器重置。 – Amogh

+0

好点,就像你说的,我们没有在mysql中设置wait_timeout。因此,它将使用28800和c3p0空闲测试周期为1800,超时为7200(如上所示)。两者都小于28800 – jprism

回答

0

我有这个问题,因为MySQL WAIT_TIMEOUT的比休眠空闲超时较小。因此,mysql会尽早关闭连接,而hibernate无法引用连接从其侧面关闭。

相关问题