【问题标题】:How to provide read and write to ColumnTransofrmer programatically in Hibernate?如何在 Hibernate 中以编程方式提供对 ColumnTransformer 的读写?
【发布时间】:2021-11-25 12:24:38
【问题描述】:
我正在使用 mysql 的 AES_ENCRYPT 和 AES_DECRYPT 函数,它以密钥为参数。但是,我不想在应用程序级别对密钥进行硬编码,也不想将其存储在 application.properties 文件中,因为我希望将密钥放在不同的服务器中。我怎样才能做到这一点?
【问题讨论】:
标签:
amazon-web-services
spring-boot
hibernate
encryption
aws-secrets-manager
【解决方案1】:
您可以实现自定义MetadataContributor,以编程方式更改属性的读/写映射。
public class MyMetadataContributor implements MetadataContributor {
public void contribute(InFlightMetadataCollector metadataCollector, IndexView jandexIndex) {
List<Selectable> selectables = metadataCollector.getEntityBindingMap().get("fqn.to.my.Entity")
.getProperty("myProperty")
.getValue()
.getSelectables();
((Column) selectables.get(0)).setCustomRead(...);
((Column) selectables.get(0)).setCustomWrite(...);
}
}