Hibernate Converter +检索Converter里面的attributename

时间:2018-02-02 03:12:13

标签: java hibernate encryption annotations

我们正在尝试使用hibernate Converter来加密/解密通过hibernate存储的数据少量列

@Convert(attributeName="myattr",converter=DataEncryptionConverter.class)
private String actualValue;

计划是根据数据类型(String,Date等)实现可重用的Converter。

然而,计划是维护一个配置模板,指示是否应打开/关闭字段加密=

方法

@Converter
public class DataEncryptionConverter implements AttributeConverter<String,String>{
    private static Logger logger = LoggerFactory.getLogger(DataEncryptionConverter.class);
    @Override
    public String convertToDatabaseColumn(String arg0) {
        logger.info("convertToDatabase>input:"+arg0);
        if(attributeName matches (TemplateList)) { 
           //check if the attributeName is part of approved TemplateList where data needs to be encrypted
           return encryptData(arg0);
        }
        else {
          return  arg0;
        }
   }
    @Override
    public String convertToEntityAttribute(String arg0) {
        logger.info("convertToEntity>input:"+arg0);
        if(attributeName matches (TemplateList)) { 
           //check if the attributeName  is part of approved TemplateList where data needs was encrypted
           return deCryptData(arg0);
        }
        else {
          return  arg0;
        }
    }

}

那么,有没有办法检索作为@Converter的一部分设置的attributeName?

0 个答案:

没有答案