@Entity 将 null passworld 发送到 h2 db

@Entity sends null passworld to h2 db

我有一个不寻常的问题。在 h2 数据库的一行中,password 是空的,但 username 不是。

@Entity
@NoArgsConstructor
public class Instructor {

    @Id
    @GeneratedValue
    @Getter
    private Long id;
    @Getter
    private String userName;

    @OneToMany(mappedBy = "instructor")
    @Getter
    private List<Course> courses;


    private String password;

    public Instructor(String name, String password){
        this.userName = name;
        this.password = password;
    }

    public void addCourse(Course coursex){
        this.courses.add(coursex);
    }
}

我尝试从密码字段中删除 @JsonIgnore,但它仍然没有将密码保存在数据库中。

您缺少 @Getter 注释。这就是 hibernate 序列化的方式。