Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 列';加密密码';不能为空?_Java_Sql_Spring Mvc_Spring Data Jpa - Fatal编程技术网

Java 列';加密密码';不能为空?

Java 列';加密密码';不能为空?,java,sql,spring-mvc,spring-data-jpa,Java,Sql,Spring Mvc,Spring Data Jpa,我正在使用Java和springdatajpa开发一个web服务。我设置了不同的端点,效果很好。现在我在post方法中实现了逻辑,并返回一个我无法解决的错误 我使用postman,当我尝试使用id、用户名、姓氏和密码发出post请求时,我收到一个错误500,服务器返回我这个错误: java.sql.SQLIntegrityConstraintViolationException:列“加密的\u密码”不能为null 您声明属性encryptedPassword不能为空。异常意味着,当您试图将该属性

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

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

java.sql.SQLIntegrityConstraintViolationException:列“加密的\u密码”不能为null


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

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

您有
@列(null=false)
用于
私有字符串加密密码并且您只传递id、用户名、姓氏和密码。这会破坏条件
nullable=false
,并导致
java.sql.SQLIntegrityConstraintViolationException:Column'encrypted_password'不能为null

解决方案

设置
@列(nullable=true)

加密密码的值传递给
私有字符串加密密码的
@列(nullable=false)
并且您只传递id、用户名、姓氏和密码。这会破坏条件
nullable=false
,并导致
java.sql.SQLIntegrityConstraintViolationException:Column'encrypted_password'不能为null

解决方案

设置
@列(nullable=true)


传递
encryptedPassword

的值引发异常,因为您将列
encryptedPassword
设置为非
null
@column(…,null=false)
)。根本原因很可能是因为未正确设置is。如果看不到端点、构建要创建的实体的逻辑和POST请求,则很难进一步诊断问题。引发异常是因为您将列
encryptedPassword
设置为非
null
@column(…,nullable=false)
)。根本原因很可能是因为未正确设置is。如果看不到端点、构建要创建的实体的逻辑和POST请求,就很难进一步诊断问题。
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;
    }
}