궁금해요

josy24

[Spring 오류] Cannot add or update a child row: a foreign key constraint fails

작성자 : josy24 작성일 : 2017.04.27 11:08:55 댓글수 : 1 조회수 : 536

데이터를 입력하는데 오류가 나서 구글링해보니 외래키가 참조하는 주 키에서 사용하는 값 이외의 값이 들어가면 이 에러를 반환한다고 합니다.


주키에서 사용하는 값을 외래키 값으로 넣어줬는데도 오류가 나는데요, 이유가 뭘까요..?


----------------------------------------------------------------------------------
[2017-04-27 11:11:27] [ERROR]『sun.reflect.NativeConstructorAccessorImpl:newInstance0(-2)』
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException
Cannot add or update a child row: a foreign key constraint fails (``.`TABLE NAME`, CONSTRAINT `R_25` FOREIGN KEY (`FOREIGN KEY NAME`) REFERENCES `TABLE NAME` (`FOREIGN KEY NAME`) ON DELETE CASCADE)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
 at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
 at com.mysql.jdbc.Util.getInstance(Util.java:408)
 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:935)
 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973)
 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909)
 at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527)
 at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680)
 at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2501)
 at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858)
 at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1197)
 at core.log.impl.PreparedStatementLoggable.execute(PreparedStatementLoggable.java:109)
 at sun.reflect.GeneratedMethodAccessor31.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:606)
 at core.log.aop.handler.DaoInfo.doAround(DaoInfo.java:95)
 at core.log.aop.reflection.profiler.AroundProfiler.invoke(AroundProfiler.java:19)
 at com.sun.proxy.$Proxy12.execute(Unknown Source)
 at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:46)
 at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74)
 at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50)
 at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
 at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198)
 at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:185)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:606)
 at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:434)
 at com.sun.proxy.$Proxy8.insert(Unknown Source)
 at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:279)
 at kr.co.cslee.common.mybatis.CommonSqlSession.insert(CommonSqlSession.java:104)
 at kr.co.cslee.admin.service.service.AdminServiceService.updateServiceListData(AdminServiceService.java:81)
 at kr.co.cslee.admin.service.web.AdminServiceController.servicetUpdateData(AdminServiceController.java:135)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:606)
 at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
 at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
 at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
 at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:743)
 at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:672)
 at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:82)
 at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:933)
 at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:867)
 at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:951)
 at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:853)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
 at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:827)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
 at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
 at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:747)
 at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:485)
 at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:410)
 at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:337)
 at org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:213)
 at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:171)
 at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
 at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
 at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:389)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
 at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
 at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452)
 at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1087)
 at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
 at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
 at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
 at java.lang.Thread.run(Thread.java:745)


[2017-04-27 11:11:27] [ERROR]『sun.reflect.NativeConstructorAccessorImpl:newInstance0(-2)』
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException

  <INSERT 쿼리문>

 
Cannot add or update a child row: a foreign key constraint fails (``.`TABLE NAME`, CONSTRAINT `R_25` FOREIGN KEY (`FOREIGN KEY NAME`) REFERENCES `TABLE NAME` (`FOREIGN KEY NAME`) ON DELETE CASCADE)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
 at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
 at com.mysql.jdbc.Util.getInstance(Util.java:408)
 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:935)
 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973)
 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909)
 at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527)
 at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680)
 at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2501)
 at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858)
 at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1197)
 at core.log.impl.PreparedStatementLoggable.execute(PreparedStatementLoggable.java:109)
 at sun.reflect.GeneratedMethodAccessor31.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:606)
 at core.log.aop.handler.DaoInfo.doAround(DaoInfo.java:95)
 at core.log.aop.reflection.profiler.AroundProfiler.invoke(AroundProfiler.java:19)
 at com.sun.proxy.$Proxy12.execute(Unknown Source)
 at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:46)
 at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74)
 at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50)
 at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
 at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198)
 at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:185)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:606)
 at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:434)
 at com.sun.proxy.$Proxy8.insert(Unknown Source)
 at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:279)
 at kr.co.cslee.common.mybatis.CommonSqlSession.insert(CommonSqlSession.java:104)
 at kr.co.cslee.admin.service.service.AdminServiceService.updateServiceListData(AdminServiceService.java:81)
 at kr.co.cslee.admin.service.web.AdminServiceController.servicetUpdateData(AdminServiceController.java:135)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:606)
 at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
 at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
 at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
 at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:743)
 at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:672)
 at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:82)
 at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:933)
 at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:867)
 at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:951)
 at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:853)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
 at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:827)
 at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
 at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
 at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:747)
 at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:485)
 at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:410)
 at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:337)
 at org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:213)
 at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:171)
 at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
 at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
 at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:389)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
 at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
 at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
 at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:452)
 at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1087)
 at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
 at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
 at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
 at java.lang.Thread.run(Thread.java:745)

첨부파일

  • 올바른 값이 넘어가고있나요?

    컨트롤러에서 찍어보시고,

    view에서 혹시 같은 변수를 다중으로 넘기고 있는지 확인해보세요

  • 댓글을 입력 하시려면 로그인 해주세요.