Cause: java.sql.SQLIntegrityConstraintViolationException: Column 'created_at' cannot be null

本文详细解析了在使用MyBatis进行数据库操作时遇到的Column 'created_at' cannot be null异常,解释了该异常的原因,并提供了正确的解决方案,即使用insertSelective方法代替insert方法,以避免插入null值导致的SQL完整性约束违反。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Cause: java.sql.SQLIntegrityConstraintViolationException: Column 'created_at' cannot be null
; Column 'created_at' cannot be null; nested exception is java.sql.SQLIntegrityConstraintViolationException: Column 'created_at' cannot be null
	at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:87) ~[spring-jdbc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) ~[spring-jdbc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-5.2.5.RELEASE.jar:5.2.5.RELEASE]
	at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:74) ~[mybatis-spring-2.0.2.jar:2.0.2]
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:440) ~[mybatis-spring-2.0.2.jar:2.0.2]
	at com.sun.proxy.$Proxy77.insert(Unknown Source) ~[na:na]
	at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:271) ~[mybatis-spring-2.0.2.jar:2.0.2]

原因是插入字段的时候使用的方法是

requestLogMapper.insert(requestLog);

应该用

requestLogMapper.insertSelective(requestLog);
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值