1.问题
Type Exception Report
Message Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException:
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: ### Error updating database. Cause: java.sql.SQLException: ORA-02292: 违反完整约束条件 (SSM.SYS_C005470) - 已找到子记录 ### The error may involve com.company.dao.ProductDao.deleteById-Inline ### The error occurred while setting parameters ### SQL: delete from product where id = ? ### Cause: java.sql.SQLException: ORA-02292: 违反完整约束条件 (SSM.SYS_C005470) - 已找到子记录 ; ]; ORA-02292: 违反完整约束条件 (SSM.SYS_C005470) - 已找到子记录 ; nested exception is java.sql.SQLException: ORA-02292: 违反完整约束条件 (SSM.SYS_C005470) - 已找到子记录 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:986) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:881) javax.servlet.http.HttpServlet.service(HttpServlet.java:661) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855) javax.servlet.http.HttpServlet.service(HttpServlet.java:742) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
Root Cause
org.springframework.dao.DataIntegrityViolationException: ### Error updating database. Cause: java.sql.SQLException: ORA-02292: 违反完整约束条件 (SSM.SYS_C005470) - 已找到子记录 ### The error may involve com.company.dao.ProductDao.deleteById-Inline ### The error occurred while setting parameters ### SQL: delete from product where id = ? ### Cause: java.sql.SQLException: ORA-02292: 违反完整约束条件 (SSM.SYS_C005470) - 已找到子记录 ; ]; ORA-02292: 违反完整约束条件 (SSM.SYS_C005470) - 已找到子记录 ; nested exception is java.sql.SQLException: ORA-02292: 违反完整约束条件 (SSM.SYS_C005470) - 已找到子记录 org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:247) org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75) org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:447) com.sun.proxy.$Proxy84.delete(Unknown Source) org.mybatis.spring.SqlSessionTemplate.delete(SqlSessionTemplate.java:311) org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:67) org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59) com.sun.proxy.$Proxy95.deleteById(Unknown Source) com.company.service.impl.ProductServiceImpl.delBatch(ProductServiceImpl.java:43) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:498) org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:338) org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:197) org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294) org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98) org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) com.sun.proxy.$Proxy96.delBatch(Unknown Source) com.company.controller.ProductController.batchDelData(ProductController.java:81) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:498) org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209) org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:871) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:777) org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:881) javax.servlet.http.HttpServlet.service(HttpServlet.java:661) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855) javax.servlet.http.HttpServlet.service(HttpServlet.java:742) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
Root Cause
java.sql.SQLException: ORA-02292: 违反完整约束条件 (SSM.SYS_C005470) - 已找到子记录 oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112) oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331) oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288) oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743) oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216) oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:955) oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1169) oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285) oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3390) com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.execute(NewProxyPreparedStatement.java:989) sun.reflect.GeneratedMethodAccessor78.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:498) org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59) com.sun.proxy.$Proxy41.execute(Unknown Source) org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:46) org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74) org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50) org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117) org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76) org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198) org.apache.ibatis.session.defaults.DefaultSqlSession.delete(DefaultSqlSession.java:213) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:498) org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:434) com.sun.proxy.$Proxy84.delete(Unknown Source) org.mybatis.spring.SqlSessionTemplate.delete(SqlSessionTemplate.java:311) org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:67) org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59) com.sun.proxy.$Proxy95.deleteById(Unknown Source) com.company.service.impl.ProductServiceImpl.delBatch(ProductServiceImpl.java:43) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:498) org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:338) org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:197) org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294) org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98) org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) com.sun.proxy.$Proxy96.delBatch(Unknown Source) com.company.controller.ProductController.batchDelData(ProductController.java:81) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:498) org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209) org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:871) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:777) org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:881) javax.servlet.http.HttpServlet.service(HttpServlet.java:661) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855) javax.servlet.http.HttpServlet.service(HttpServlet.java:742) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
2.问题分析
主外键关联问题,需要删除子表中的所有记录,再删除主表的记录。
也可以通过级联删除,删除主表数据,连带当前记录的从表数据全部删除。
3.解决方式
在创建从表的时候,在外键约束的最后加上on delete cascade。