在我看来,对于只读操作,我们的一些代码还没有启动事务,我们通过JPA/Hibernate的查询以及直接的SQL似乎都可以工作。我们的框架会打开一个hibernate/jpa会话,但是对于遗留代码中的一些地方,我们发现没有事务被打开。
似乎最终发生的情况是,只要不使用EntityManager.persist和EntityManager.merge,代码通常就会运行。但是,偶尔(可能是1/10)次servlet容器失败,并显示以下错误...
Failed to load resource: the server responded with a status of 500 (org.hibernate.exception.JDBCConnectionException: The last packet successfully received from the server was 314,024,057 milliseconds ago. The last packet sent successfully to the server was 314,024,057 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.) 据我所知,在我们的应用程序代码中,只有少数在查询之前没有启动事务的地方会出现这个问题。是否有人认为可能是正在运行的非事务性查询导致了这种行为?
仅供参考这里是我们的堆栈。
-Guice -Guice-Persist Servlet -MySql 5.1.63 -Hibernate/C3P0 4.1.4最终-Jetty
发布于 2013-04-18 05:03:15
是的,我想。
如果您在未打开事务的情况下启动查询,则此事务将由底层自动打开。这个带有打开的事务的连接将返回到连接池,并提供给另一个用户,该用户将接收到一个已经打开的事务的连接,这可能会导致状态不一致。
在我的公司里,我们在过去的只读非事务性查询中遇到了很多问题,并调整了我们的框架来处理这个问题。此外,我们与BoneCP开发人员进行了交谈,他们接受了开发一组功能来帮助处理此问题,如自动回滚未提交的事务返回池,并打印堆栈跟踪哪个方法忘记提交事务。
这里讨论了这个问题:http://jolbox.com/forum/viewtopic.php?f=3&t=98
https://stackoverflow.com/questions/11313792
复制相似问题