ORACL报错“违反完整约束条件”

org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL [insert into t_vodcmdinfo(vod_cmd_info_id,vod_cmd_log_id,cust_no,subscriberid,package_id,offer_id,deviceid,start_time,end_time)values(?,?,?,?,?,?,?,?,?)]; ORA-02291: 违反完整约束条件 (XMTEST.F_T_VODCMDINFO_LOGID) - 未找到父项关键字

; nested exception is java.sql.SQLException: ORA-02291: 违反完整约束条件 (XMTEST.F_T_VODCMDINFO_LOGID) - 未找到父项关键字


at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:228)

at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)

at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:607)

at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:792)

at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:850)

at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:854)

at com.topdvte.vodsea.client.dao.VodCmdInfoDao.insert(VodCmdInfoDao.java:24)

at com.topdvte.vodsea.client.dao.VodCmdInfoDaoTest.testInsert(VodCmdInfoDaoTest.java:28)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at junit.framework.TestCase.runTest(TestCase.java:168)

at junit.framework.TestCase.runBare(TestCase.java:134)

at junit.framework.TestResult$1.protect(TestResult.java:110)

at junit.framework.TestResult.runProtected(TestResult.java:128)

at junit.framework.TestResult.run(TestResult.java:113)

at junit.framework.TestCase.run(TestCase.java:124)

at junit.framework.TestSuite.runTest(TestSuite.java:232)

at junit.framework.TestSuite.run(TestSuite.java:227)

at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)

at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)

at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

Caused by: java.sql.SQLException: ORA-02291: 违反完整约束条件 (XMTEST.F_T_VODCMDINFO_LOGID) - 未找到父项关键字


at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:180)

at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208)

at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:543)

at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1451)

at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:862)

at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:1846)

at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1771)

at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2361)

at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:422)

at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:102)

at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:798)

at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:591)

... 24 more

总结:

1、表t_vodcmdinfo和t_vodcmdLog存在外键关联,必须先插入父表t_vodcmdLog数据,在插入子表t_vodcmdinfo数据,并且父子表的主外键值一定要相同

2、存在外键关联时,做删除时,先删除子表,在删除父表

你可能感兴趣的:(ORACL报错“违反完整约束条件”)