網(wǎng)站首頁(yè) 編程語(yǔ)言 正文
? ? 為了給項(xiàng)目其他人提供模塊的swagger服務(wù),在本地window里安裝了ubuntu子系統(tǒng),將模塊服務(wù)運(yùn)行在Tomcat中,奇怪的是,每天晚上下班時(shí)啟動(dòng)服務(wù),早上上班來(lái)就會(huì)看到日志catalina.out文件都會(huì)暴增到10G左右,今天剛好有空,來(lái)查一查這個(gè)問(wèn)題。。。?
org.springframework.dao.DataIntegrityViolationException:
### Error updating database. Cause: com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Incorrect datetime value: '1' for column 'created' at row 1
### The error may involve com.xxx.xxx.repository.xxx.deleteByPrimaryKey-Inline
### The error occurred while setting parameters
### SQL: DELETE FROM xxxx WHERE id = ? AND cid = ? AND xxx_id = ? AND xxx_num = ? AND created = ? AND xxx = ?
### Cause: com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Incorrect datetime value: '1' for column 'created' at row 1
; Data truncation: Incorrect datetime value: '1' for column 'created' at row 1; nested exception is com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Incorrect datetime value: '1' for column 'created' at row 1
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:104)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
at com.sun.proxy.$Proxy45.delete(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.delete(SqlSessionTemplate.java:310)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:68)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
at com.sun.proxy.$Proxy96.deleteByPrimaryKey(Unknown Source)
? ? 首先日志中出現(xiàn)大量DELETE FROM 的SQL語(yǔ)句,但是參數(shù)卻有點(diǎn)怪怪的。。。
JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@3cd9a44f] will not be managed by Spring
==> Preparing: DELETE FROM xxx WHERE id = ? AND cid = ? AND xxx_id = ? AND xxx_num = ? AND created = ? AND xxx = ?
==> Parameters: 1(Long), 1(Long), 1(Long), 1(Long), 1(Long), 1(Long)
? ? 對(duì)應(yīng)的代碼部分是:?
xxxxMapper.deleteByPrimaryKey(v.getId());
? ? 這個(gè)是Mybatis自帶的根據(jù)主鍵ID刪除表數(shù)據(jù)的方法啊,怎么會(huì)出現(xiàn)問(wèn)題???
package tk.mybatis.mapper.common.base.delete;
import org.apache.ibatis.annotations.DeleteProvider;
import tk.mybatis.mapper.annotation.RegisterMapper;
import tk.mybatis.mapper.provider.base.BaseDeleteProvider;
/**
* 通用Mapper接口,刪除
*
* @param 不能為空
* @author liuzh
*/
@RegisterMapper
public interface DeleteByPrimaryKeyMapper {
/**
* 根據(jù)主鍵字段進(jìn)行刪除,方法參數(shù)必須包含完整的主鍵屬性
*
* @param key
* @return
*/
@DeleteProvider(type = BaseDeleteProvider.class, method = "dynamicSQL")
int deleteByPrimaryKey(Object key);
}
? ? 經(jīng)過(guò)排查,發(fā)現(xiàn)是因?yàn)樵趯?shí)體類的id參數(shù),沒(méi)有配置主鍵ID的注解,導(dǎo)致mybatis找不到這條刪除語(yǔ)句的主鍵,所以才會(huì)出現(xiàn)這個(gè)問(wèn)題。
? ? 需,加上@Id注解,表明該id是主鍵ID,才能保證刪除邏輯執(zhí)行正常。
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
? ? ps:當(dāng)然,也可以直接手寫(xiě)SQL語(yǔ)句,進(jìn)行刪除(不推薦)
@Delete("DELETE FROM xxxx WHERE id=#{id}")
void deleteInfoById(@Param("id") Long id);
?
原文鏈接:https://zhangdaopin.blog.csdn.net/article/details/118149475
相關(guān)推薦
- 2022-06-01 python中使用正則表達(dá)式的方法詳解_python
- 2022-06-17 C語(yǔ)言深入講解內(nèi)存操作問(wèn)題_C 語(yǔ)言
- 2022-02-09 C++學(xué)習(xí)之IO流(輸入輸出流)詳解_C 語(yǔ)言
- 2024-07-15 Spring Boot多環(huán)境指定yml或者properties
- 2022-10-26 Flutter?EventBus事件總線的應(yīng)用詳解_Android
- 2022-03-29 Python?dict的使用誤區(qū)你知道嗎_python
- 2022-07-13 Stream的源碼簡(jiǎn)單解析
- 2022-03-25 C++實(shí)現(xiàn)希爾排序算法實(shí)例_C 語(yǔ)言
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過(guò)濾器
- Spring Security概述快速入門(mén)
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支