首页 » MySQL » org.springframework.dao.DataIntegrityViolationException:

org.springframework.dao.DataIntegrityViolationException:

原文 http://blog.csdn.net/MCJ_2017/article/details/79210489

2018-01-31 02:01:18阅读(254)

贡献一个简单bug,在往数据库添加记录的时候报错

org.springframework.dao.DataIntegrityViolationException: 
### Error updating database.  Cause: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'model_belong_type' at row 1
### The error may involve com.louddt.ldp.analysis.model.mapper.ModelInfoMapper.updateByPrimaryKeySelective-Inline
### The error occurred while setting parameters
### SQL: update ldp_analy_model_info      SET model_type = ?,                       model_name = ?,                       model_trade_type = ?,                       model_business_type = ?,                       audit_matters = ?,                       model_purpose = ?,                       input_data = ?,                       analysis_steps = ?,                       regulation = ?,                       model_sql = ?,                              model_belong_type = ?,                       other_model = ?      where id = ?
### Cause: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'model_belong_type' at row 1
; SQL []; Data truncation: Data too long for column 'model_belong_type' at row 1; nested exception is com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'model_belong_type' at row 1
	at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:102)
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
	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:74)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:399)
	at com.sun.proxy.$Proxy13.update(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.update(SqlSessionTemplate.java:269)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:54)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
	at com.sun.proxy.$Proxy44.updateByPrimaryKeySelective(Unknown Source)

org.springframework.dao.DataIntegrityViolationException:org.springframework.dao.DataIntegrityViolationException:org.springframework.dao.DataIntegrityViolationException:org.springframework.dao.DataIntegrityViolationException:

看代码标红的部分,多次提到错误原因

Data too long for column 'model_belong_type'
大概意思就是对 model_belong_type 这个字段数据太长,然后我去检查了一下表信息,发现这个字段的长度设置为1,然而我在赋值的时候,这个字段的长度为4个字段,赋值的数据字段太长了,超过了这个字段的定义长度,所以才报了data too lang!

希望可以帮到一些人!


最新发布

CentOS专题

关于本站

5ibc.net旗下博客站精品博文小部分原创、大部分从互联网收集整理。尊重作者版权、传播精品博文,让更多编程爱好者知晓!

小提示

按 Ctrl+D 键,
把本文加入收藏夹