我開發了一個帶GWT的Web應用程序。我只創建一個EntityManagerFactory(單例),但我不知道什麼時候必須關閉它。我按照這個網頁的指示:http://javanotepad.blogspot.com/2007/05/jpa-entitymanagerfactory-in-web.html,且8個小時沒有進入我的應用程序後,我有錯誤:在Web應用程序中管理EntityManagerFactory
78616509 [http-9080-Processor4] ERROR org.hibernate.transaction.JDBCTransaction - JDBC begin failed
com.mysql.jdbc.CommunicationsException: The last packet successfully received from the server was 44,115,64
4 milliseconds ago. The last packet sent successfully to the server was 44,115,644 milliseconds ago. is lo
nger 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 tim
eouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1112)
後2或3次嘗試一切工作正常。如果我在每次事務之後關閉EntityManagerFactory,我沒有問題,但我不想那樣做。我想知道如何管理EntityManagerFactory循環。
在此先感謝。