我經歷了很多解決方案,我的問題已經解決,但一段時間後連接超時或斷開連接。2天后,我得到了解決方案,解決了我的問題。
許多解決方案建議使用autoReconnect = true但是當我通過文檔。我看到在描述autoReconnect的參數源以下文字:
使用此功能不推薦,因爲它有當我在Hibernate代碼看起來與會話狀態和數據一致性
副作用。 Hibernate的基本連接機制不支持重連,必須使用H3C0連接池(本身並不總是支持重連)。
但是一旦使用過H3C0,默認行爲似乎是處理請求,如果連接死了,那麼用戶會看到錯誤 - 但至少它會重新連接下一個請求。我想一個錯誤比無限錯誤更好,但仍然不如零錯誤。事實證明,需要optiontestConnectionOnCheckout-文檔不建議這麼做,因爲在請求之前測試連接可能導致性能下降。當然,軟件首先必須工作,其次才需要快速工作。
因此,要總結,要獲得一個連接的「工作」(我定義爲包括處理由沒有錯誤重新連接掉線):在「hibernate.cfg.xml中」:
<!-- hibernate.cfg.xml -->
<property name="c3p0.min_size">5</property>
<property name="c3p0.max_size">20</property>
<property name="c3p0.timeout">1800</property>
<property name="c3p0.max_statements">50</property>
<!-- no "connection.pool_size" entry! -->
然後創建文件「c3p0.properties」,它必須是在類路徑的根(即,沒有辦法來覆蓋它的應用程序的特定部分):
c3p0.properties
C3P0。
1. Add
<property name="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
Also dont forget to place the c3p0-0.9.1.jar in the classpath.
2. Instead of using that c3p0.properties file, couldn't you just use this property in your hibernate.cfg.xml:
<property name="hibernate.c3p0.validate">true</property>
Also checkout the last post on this page:
https://forum.hibernate.org/viewtopic.php?p=2399313
If all these not work than go [more][1] and read in detail
[1]: http://hibernatedb.blogspot.in/2009/05/automatic-reconnect-from-hibernate-to.html
請幫助https://stackoverflow.com/questions/47011116/the-last-packet-sent- - :testConnectionOnCheckout如果不是有更多可能的解決方案這個解決方案沒有工作=真
成功到服務器是-70-400-003-milliseconds-ag – Tony 2017-10-30 09:05:50