MySQLIntegrityConstraintViolationException:列“”不能为空
MySQLIntegrityConstraintViolationException: Column '' cannot be null
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())
错误
"Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'surplusAmount' cannot be null"
当我将 when inventoryId=#{item.inventoryId} and materialTypeId=#{item.materialTypeId}
修改为 when inventoryId=#{item.inventoryId}
时,错误消失了。
但是我需要拖车参数inventoryId和materialTypeId才能决定inventoryId。所以有人可以给我一些答案吗?
执行的查询从 table_inventory_material
到 inventoryId
中选择记录,并使用每个 materialTypeId
的指定数据更新它们。
出现问题是因为对于您在列表中传递的某些 inventoryId
,数据库比您在作为参数传递的列表中提供的 materialTypeId
多。
因此生成的 case 语句为缺少的 materialTypeId
生成 NULL
并且尝试将 surplusAmount
设置为 NULL
导致错误。
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())
错误
"Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'surplusAmount' cannot be null"
当我将 when inventoryId=#{item.inventoryId} and materialTypeId=#{item.materialTypeId}
修改为 when inventoryId=#{item.inventoryId}
时,错误消失了。
但是我需要拖车参数inventoryId和materialTypeId才能决定inventoryId。所以有人可以给我一些答案吗?
执行的查询从 table_inventory_material
到 inventoryId
中选择记录,并使用每个 materialTypeId
的指定数据更新它们。
出现问题是因为对于您在列表中传递的某些 inventoryId
,数据库比您在作为参数传递的列表中提供的 materialTypeId
多。
因此生成的 case 语句为缺少的 materialTypeId
生成 NULL
并且尝试将 surplusAmount
设置为 NULL
导致错误。