【发布时间】:2011-09-20 13:35:23
【问题描述】:
我使用 GWT 开发了一个 Web 应用程序。我只创建了一个 EntityManagerFactory (单例),但我不知道什么时候必须关闭它。我已按照此网站的说明进行操作:http://javanotepad.blogspot.com/2007/05/jpa-entitymanagerfactory-in-web.html,但 8 小时后没有进入我的应用程序,我遇到了错误:
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 循环。
提前致谢。
【问题讨论】: