gpt4 book ai didi

MySQLIntegrityConstraintViolationException : Column '' cannot be null

转载 作者:行者123 更新时间:2023-11-29 17:01:06 25 4
gpt4 key购买 nike

mapper:
<update id="updateSurplusAmountByPrimaryKeyAndMaterialTypeId"
parameterType="java.util.List">
update db_logistics.table_inventory_material
set surplusAmount=
<foreach collection="list" item="item" index="index"
separator=" " open="case" close="end">
when inventoryId=#{item.inventoryId} and materialTypeId=#
{item.materialTypeId} then #{item.surplusAmount,jdbcType=INTEGER}
</foreach>
where inventoryId in
<foreach collection="list" index="index" item="item"
separator="," open="(" close=")">
#{item.inventoryId,jdbcType=BIGINT}
</foreach>
</update>
fun updateSurplusAmountByPrimaryKeyAndMaterialTypeId(records:
List<InventoryMaterial>): Int
data class InventoryMaterial(
var inventoryId: Int = 0,
var materialTypeId: Int = 0,
var surplusAmount: Int = 0,
var consumeSpeed: Float = 0f,
var consumeAlarmDayCount: Int = 0,
var updateDataTime: LocalDateTime = LocalDateTime.now())

错误

“由以下原因引起:com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:列‘surplusAmount’不能为空”

当我将when inventoryId=#{item.inventoryId}和materialTypeId=#{item.materialTypeId}修改为when inventoryId=#{item.inventoryId}时,然后错误就消失了。但我需要拖曳参数inventoryId和materialTypeId可以决定inventoryId。有人可以给我一些答案吗?

最佳答案

执行的查询通过 inventoryIdtable_inventory_material 选择记录,并使用每个 materialTypeId 的指定数据更新它们。

出现此问题的原因是,对于您在列表中传递的某些 inventoryId,数据库的 materialTypeId 数量多于您在作为参数传递的列表中提供的数量。

因此,生成的 case 语句针对缺少的 materialTypeId 生成 NULL,并尝试将 surplusAmount 设置为 NULL导致错误。

关于MySQLIntegrityConstraintViolationException : Column '' cannot be null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52256414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com