使用@PatchRequest仅更新某些字段

问题描述 投票:0回答:1

我试图使用@PatchRequest测试我的API,我收到以下错误。

SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/intranet-api] threw exception [Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: could not execute batch; SQL [update portal.dbo.DANCE_MASTER set name=?, age=?, gender=?, grade=?,status=?, updated_by=?, updated_ts=? where id=?]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute batch] with root cause
    java.sql.BatchUpdateException: Cannot insert the value NULL into column 'name', table 'ctcportal1.dbo.DANCE_MASTER'; column does not allow nulls. UPDATE fails.

从显示的错误,似乎我应该为所有字段提供更新的值。但是,我只想更新表中的某些字段。

spring rest api
1个回答
0
投票

java.sql.BatchUpdateException:无法将值NULL插入列'name',表'ctcportal1.dbo.DANCE_MASTER';列不允许空值。更新失败。

错误信息清楚地表明,不能将值NULL插入列'name'。检查DANCE_MASTER表定义并提供所有必需列的值。

您还可以通过对数据库运行以下查询来获取值。用适当的值替换问号。

update portal.dbo.DANCE_MASTER 
set name=?, 
age=?, 
gender=?, 
grade=?,
status=?, 
updated_by=?, 
updated_ts=? 
where id=?
© www.soinside.com 2019 - 2024. All rights reserved.