在ProductImgDaoTest的时候报错
来源:8-1 商品添加之Dao层的实现

qq_晴风_4
2019-05-04
console显示:
五月 04, 2019 5:34:50 下午 com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager
信息: Initializing c3p0 pool… com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 2, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 10000, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, dataSourceName -> 1b60zt2a2104hqy41iegnxh|1d2adfbe, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> com.mysql.jdbc.Driver, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1b60zt2a2104hqy41iegnxh|1d2adfbe, idleConnectionTestPeriod -> 60, initialPoolSize -> 5, jdbcUrl -> jdbc:mysql://localhost:3306/o2o?useUnicode=true&characterEncoding=utf8, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 60, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 30, maxStatements -> 100, maxStatementsPerConnection -> 3, minPoolSize -> 10, numHelperThreads -> 3, numThreadsAwaitingCheckoutDefaultUser -> 0, preferredTestQuery -> select1, properties -> {user=******, password=******}, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false ]
2019-05-04 17:34:51.231 [main] DEBUG c.xmut.o2o.dao.ProductImgDao.batchInsertProductImg - ==> Preparing: INSERT INTO tb_product_img(img_addr,img_desc,priority, create_time,product_id) VALUES ( ?, ?, ?, ?, ? ) , ( ?, ?, ?, ?, ? )
2019-05-04 17:34:51.261 [main] DEBUG c.xmut.o2o.dao.ProductImgDao.batchInsertProductImg - ==> Parameters: 图片1(String), 测试图片1(String), 1(Integer), 2019-05-04 17:34:50.877(Timestamp), 1(Long), 图片2(String), null, 1(Integer), 2019-05-04 17:34:50.877(Timestamp), 1(Long)
五月 04, 2019 5:34:51 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
五月 04, 2019 5:34:51 下午 org.springframework.jdbc.support.SQLErrorCodesFactory
信息: SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase, Hana]
2019-05-04 17:34:51.318 [main] DEBUG com.xmut.o2o.dao.ProductImgDao.queryProductImgList - ==> Preparing: SELECT product_img_id, img_addr, img_desc, priority, create_time, product_id FROM tb_product_img WHERE product_id=? ORDER BY product_img_id ASC
2019-05-04 17:34:51.318 [main] DEBUG com.xmut.o2o.dao.ProductImgDao.queryProductImgList - > Parameters: 1(Long)
2019-05-04 17:34:51.334 [main] DEBUG com.xmut.o2o.dao.ProductImgDao.queryProductImgList - < Total: 0
2019-05-04 17:34:51.337 [main] DEBUG c.x.o.d.ProductImgDao.deleteProductImgByProductId - ==> Preparing: DELETE FROM tb_product_img WHERE product_id = ?
2019-05-04 17:34:51.338 [main] DEBUG c.x.o.d.ProductImgDao.deleteProductImgByProductId - > Parameters: 1(Long)
2019-05-04 17:34:51.339 [main] DEBUG c.x.o.d.ProductImgDao.deleteProductImgByProductId - < Updates: 0
然后在Junit显示:
org.springframework.dao.DataIntegrityViolationException:
Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (o2o
.tb_product_img
, CONSTRAINT fk_proimg_product
FOREIGN KEY (product_id
) REFERENCES tb_product
(product_id
))
我查了一下午还是没有发现问题只能来向老师求救了,表和代码没有发现问题,不懂出错在哪
1回答
-
qq_晴风_4
提问者
2019-05-04
已解决
122019-05-09
相似问题