2017-08-29 41 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無法引用連接從其側面關閉。

相關問題