0

我有一个名为 Customer 的实体模型类,它具有以下字段列,用于存储由 Postgresql 中的 PgCrypto 生成的用户密码哈希:

@Entity(name = "customers")
@Table(name = "customers")
public class Customer implements Serializable {

    /**
     *
     */
    private static final long serialVersionUID = -3265467376787297897L;

    @JsonIgnore
    @Id
    @GeneratedValue(generator = "user_id_generator")
    @SequenceGenerator(name = "user_id_generator", sequenceName = "user_id_sequence", initialValue = 1)
    private Long id;
    private String email;
    //@JsonIgnore
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @ColumnTransformer(write = "digest(?, 'sha512')", read = "encode(password, 'hex')")
    @Column(columnDefinition = "bytea", updatable = false)
    private String password;
    @ColumnTransformer(write = "pgp_sym_encrypt(?, current_setting('encrypt.key'), 'cipher-algo=aes128')", read = "pgp_sym_decrypt(phone, current_setting('encrypt.key'), 'cipher-algo=aes128')")
    @Column(columnDefinition = "bytea")
    private String phone;
    @ColumnTransformer(write = "pgp_sym_encrypt(?, current_setting('encrypt.key'), 'cipher-algo=aes128')", read = "pgp_sym_decrypt(address, current_setting('encrypt.key'), 'cipher-algo=aes128')")
    @Column(columnDefinition = "bytea")
    private String address;


    public Long getId() {
        return id;
    }

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

    public String getEmail() {
        return email;
    }

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

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }
}

现在我在通过客户实体模型类的存储库为用户保存任何其他字段时遇到问题,它也会保存密码哈希,生成存储在数据库中的新密码哈希。有没有办法告诉 Spring 在保存实体模型时忽略某个字段,或者有没有办法更新列设置,例如更改“列”注释中的“可更新”?

4

0 回答 0