gpt4 book ai didi

java - 'encrypted_password' 列不能为空?

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

我正在使用 Javaspring-data-jpa 开发 Web 服务。我设置了不同的端点,效果很好。现在我在 post 方法中实现了逻辑,并返回了一个我无法解决的错误。

我使用postman,当我尝试使用 id、用户名、姓氏和密码发出 post 请求时,我收到错误 500,服务器返回此错误:

java.sql.SQLIntegrityConstraintViolationException: Column 'encrypted_password' cannot be null

package com.nicolacannata.Appws.entity;

import javax.persistence.*;
import java.io.Serializable;

@Entity(name="users")
public class UserEntity implements Serializable{

private static final long serialVersionUID = 8076405899207283205L;

@Id
@GeneratedValue
private long id;

@Column(nullable = false)
private String userId;

@Column(nullable = false, length = 50)
private String firstName;

@Column(nullable = false, length = 50)
private String lastName;

@Column(nullable = false, length = 50)
private String email;

@Column(nullable = false)
private String encryptedPassword;

private String emailVerificationToken;

@Column(nullable = false)
private boolean emailVerificationStatus = false;

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public String getUserId() {
return userId;
}

public void setUserId(String userId) {
this.userId = userId;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getEncryptedPassword() {
return encryptedPassword;
}

public void setEncryptedPassword(String encryptedPassword) {
this.encryptedPassword = encryptedPassword;
}

public String getEmailVerificationToker() {
return emailVerificationToken;
}

public void setEmailVerificationToker(String emailVerificationToker) {
this.emailVerificationToken = emailVerificationToker;
}

public boolean isEmailVerificationStatus() {
return emailVerificationStatus;
}

public void setEmailVerificationStatus(boolean emailVerificationStatus) {
this.emailVerificationStatus = emailVerificationStatus;
}
}

最佳答案

您声明属性 encryptedPassword 不能为 null。该异常意味着,当您尝试将其保存到数据库时,该属性为 null。要么您忘记设置此属性。或者您设置了它(您称为 setter),但新值是 null。要解决此问题,请在保存到数据库之前将此属性设置为 not-null 值。

关于java - 'encrypted_password' 列不能为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57645374/

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