我需要对某些列进行加密和解密。
@Entity
@Table(name = "Person")
@Data
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID", unique = true, nullable = false)
private Long id;
@Column(name = "NAME", columnDefinition = "varchar")
@ColumnTransformer(read = "pgp_sym_decrypt(decode(NAME, 'hex'), 'key')", write = "encode(pgp_sym_encrypt(?, 'key'), 'hex')")
private String name;
@ManyToOne
@JoinColumn(name = "PARENT_ID")
private Person parent;
}
当我使用PersonRepository.findOneByParentId(10L);并查看日志sql是
select person0_."id" as id1_99_, pgp_sym_decrypt(decode(NAME, 'hex'), 'key') as name2_99_ from "public"."person" person0_ left outer join "public"."person" person1_ on person0_."parent_id"=person1_."id" where person1_."id"=?
此错误消息
ERROR: column reference "name" is ambiguous
为什么 @ColumnTransformer 不添加列“名称”的表别名,我该怎么办?