gpt4 book ai didi

java - 无法执行语句; SQL [不适用];约束[空];嵌套异常是 org.hibernate.exception.ConstraintViolationException :

转载 作者:太空宇宙 更新时间:2023-11-04 09:06:48 25 4
gpt4 key购买 nike

我正在通过此类更新一些值,createdBy和lastModifiedBy的值不是强制更新的。所以,我不会从 postman 那里传递这些值。它接受lastModifiedBy 列,但当我没有传递createdBy 值时,它显示sql 异常。为什么会发生这种情况?

public class SubTeamMembersUpdateRequestDTO {

private Long id;
private Long subTeamId;
private Long userId;
private Integer target;
private Date startDate;
private Date endDate;
private String memberType;
private boolean isActive;

private String createdBy;
private String lastModifiedBy;
}

控制台如下所示:

at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.9.RELEASE.jar:5.1.9.RELEASE] at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139) ~[spring-tx-5.1.9.RELEASE.jar:5.1.9.RELEASE] ... 111 common frames omitted Caused by: java.sql.SQLIntegrityConstraintViolationException: Column 'created_by' cannot be null at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:117) ~[mysql-connector-java-8.0.17.jar:8.0.17] at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.17.jar:8.0.17] at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.17.jar:8.0.17] at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953) ~[mysql-connector-java-8.0.17.jar:8.0.17] at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1092) ~[mysql-connector-java-8.0.17.jar:8.0.17] at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1040) ~[mysql-connector-java-8.0.17.jar:8.0.17] at com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:1340) ~[mysql-connector-java-8.0.17.jar:8.0.17] at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:1025) ~[mysql-connector-java-8.0.17.jar:8.0.17] at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61) ~[HikariCP-3.2.0.jar:na] at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java) ~[HikariCP-3.2.0.jar:na] at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:175) ~[hibernate-core-5.3.10.Final.jar:5.3.10.Final] ... 160 common frames omitted

最佳答案

据我了解,数据库中的“createdBy”字段已经不为空(因为这是一个更新请求)。我想你应该看看数据库的保存方法。看起来您在更新行时尝试将“createdBy”字段设置为 null,并且 mysql 抛出异常。也许您将 null (只需从 SubTeamMembersUpdateRequestDTO.createBy 复制)设置为数据库模型并保存模型?

关于java - 无法执行语句; SQL [不适用];约束[空];嵌套异常是 org.hibernate.exception.ConstraintViolationException :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60136474/

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