在我的项目中,我有很多嵌套对象,几天后服务器在每次查询执行时都变得非常慢。
我已经从 object.save(flush:true) 中删除了 flush:true,这应该避免对象立即与数据库持久化,因为我不需要对象 id,我认为最好让 hibernate 决定何时刷新和犯罪。
但即使在此之后,我也遇到了一些与数据库相关的死锁问题,我收到了错误:
Timeout waiting for idle object. Stacktrace follows:
org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionException: JDBC beg
in failed:
at SecurityFilters$_closure1_closure2_closure4.doCall(SecurityFilters.groovy:13)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: org.hibernate.TransactionException: JDBC begin failed:
... 4 more
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot get a connection, pool error Timeout waiting for idle object
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:114)
at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
... 4 more
Caused by: java.util.NoSuchElementException: Timeout waiting for idle object
at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1167)
at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:106)
... 5 more
在深入研究了这个问题之后,一些人建议在几次执行之后我应该手动刷新休眠会话。
由于我已经从保存调用中删除了对象刷新,我应该去吗
session.flush()
session.clear()
清除休眠会话,如果是,那么这两个方面有什么区别。