簡體   English   中英

偶爾讓JDBC開始事務失敗,然后自動恢復

[英]Occasionally getting JDBC begin transaction failed, then recovers automatically

我們使用多個 spring 數據源連接多個數據庫。 我們只是偶爾收到以下錯誤,然后過一段時間一切都會自動重新工作

o.h.e.j.s.SqlExceptionHelper.logExceptions:129 - SQL Error: 0, SQLState: null
org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is org.hibernate.TransactionException: JDBC begin transaction failed:
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 84,250,518 milliseconds ago.  The last packet sent successfully to the server was 84,250,518 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.

發現問題,由於一些不活動數據源變得空閑並從池中失去連接。

解決方案是在 spring 應用程序屬性文件中添加驗證查詢並設置 testOnBorrow true

validationQuery="select 1"
testOnBorrow=true

autoReconect = true 在這種情況下沒有幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM