我有一个问题是使用deleteInBatch从db中删除项目.
我有一个对象A有一个对象B列表,如:
class A {
private List
该列表包含7k多个元素.
所以现在我必须删除A及其所有元素.我试过通过deleteInBatch,但我得到了
org.springframework.web.util.NestedServletException: Handler processing Failed;
nested exception is java.lang.StackOverflowError
使用sipmle delete方法删除项目有效,但需要5分钟以上.
我的删除代码是:
public void delete(Long id) {
A a = repository.findOne(id);
deleteElements(a);
repository.delete(a);
}
private void deleteElements(A a) {
repository.deleteInBatch(a.getListOfB);
}
有没有一个很好的解决方案来加快删除过程或如何更改,以便deleteinbatch不占用所有休眠堆栈 – 不增加它?
完整的Stacktrace:
org.springframework.web.util.NestedServletException: Handler processing Failed; nested exception is java.lang.StackOverflowError
org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1259)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:163)
net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:206)
net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:179)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
等等…
root cause
java.lang.StackOverflowError
org.hibernate.hql.internal.ast.tree.sqlNode.sqlNode.java:34)
sun.reflect.GeneratedConstructorAccessor36.newInstance(Unknown Source)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
java.lang.reflect.Constructor.newInstance(Constructor.java:526)
java.lang.Class.newInstance(Class.java:379)
org.hibernate.hql.internal.ast.sqlASTFactory.create(sqlASTFactory.java:256)
antlr.ASTFactory.create(ASTFactory.java:153)
antlr.ASTFactory.create(ASTFactory.java:186)
org.hibernate.hql.internal.antlr.HqlsqlBaseWalker.logicalExpr(HqlsqlBaseWalker.java:2018)
org.hibernate.hql.internal.antlr.HqlsqlBaseWalker.logicalExpr(HqlsqlBaseWalker.java:2026)
org.hibernate.hql.internal.antlr.HqlsqlBaseWalker.logicalExpr(HqlsqlBaseWalker.java:2026)
等等….
最佳答案
原文链接:/spring/431548.html