java - Springboot JPA - 从数据库中检索实体时调用属性上的函数
问题描述
我正在为我的应用程序使用带有休眠功能的 Spring Boot。我的应用程序有一些敏感数据,因此它们以加密形式存储在数据库中。
但是,我的应用程序希望它们被解密。通常这是通过数据库中的过程完成的。在普通的旧 SQL 中,这可以毫无问题地完成。
@Entity
@Table(name = "my_table")
@Data
@Component
public class myObject implements Serializable
{
//This is stored in DB decrypted. I want this to be decrypted when I fetch the records.
@Column(name = "sensitive_data")
private String sensitiveData;
//Other unrelated properties
}
我可以在将对象加载到我的应用程序后进行解密,如下所示。但是,这将导致我需要的每个对象的数据库调用越来越多。这也会减慢我的应用程序的速度。所以我想在从数据库加载我的对象时找到一种方法来获取解密值。
@Repository
public interface myRepo extends JpaRepository<myObject , String>
{
//(1)I use this for getting the list of objects from database
@Query("SELECT obj FROM myObject obj WHERE obj.statusCode =:status_code ")
List<myObject> getmyObjects(@Param("status_code") String status_code);
//(2)I use this to get decrypted value after when I perform operations on objects received from (1)
@Procedure("decrypt_function")
String getDecrptedValue(@Param("encrypted") String encrypted);
}
需要明确的是,sensitive_data
列将具有类似“212AFD232323DGGFF”的值。decrypt_function
但是我需要在从数据库加载对象时调用解密的值。
有没有办法做到这一点?提前致谢。:)
解决方案
推荐阅读
- python - 不支持的格式字符“m”
- php - 一对多关系的总价格(laravel)
- tfs - TFS 2017 管理员控制台未打开,装配错误
- r - 两个数字向量上的全对全 setdiff,具有接受匹配的数字阈值
- python - 如何将 listiterator 对象转换为树对象?
- jquery - 两个月,同时在引导程序的日期选择器中选择日期
- batch-file - 从所有用户的桌面删除所有图标的批处理脚本
- vba - 编写在模块生成#VALUE 中的公式
- java - 在启动 Activity 时传递 InputConnection 对象
- node.js - 将 NodeJS 应用程序变量绑定到 Pivotal Cloud Foundry 服务