是否可以使用@Formula 注释检索自定义对象?
Is it possible to retrieve a custom Object with @Formula annotation?
是否可以检索带有@Formula 注释的自定义对象?我想在我的一个实体中检索特定 table 的代码和描述:
@Formula(value = "(SELECT s.cod_setor AS code, s.descricao_setor AS description"
+ " FROM service.sector s LEFT JOIN service.employee e "
+ " ON (s.cpf = e.cpf) "
+ " WHERE e.cpf=cpf)")
private SectorDTO sector;
可以用 @PostLoad
用法来完成。
@Formula(value = "(SELECT concat(s.cod_setor, '_', s.descricao_setor)"
+ " FROM service.sector s LEFT JOIN service.employee e "
+ " ON (s.cpf = e.cpf) "
+ " WHERE e.cpf=cpf)")
// select multiple fields as one string where values are divided by '_'
private String sectorFormula;
@Transient
private SectorDTO sector;
@PostLoad
private void onLoad() {
String[] parts = sectorFormula.split("_");
this.sector = new SectorDTO(parts[0], parts[1]);
}
是否可以检索带有@Formula 注释的自定义对象?我想在我的一个实体中检索特定 table 的代码和描述:
@Formula(value = "(SELECT s.cod_setor AS code, s.descricao_setor AS description"
+ " FROM service.sector s LEFT JOIN service.employee e "
+ " ON (s.cpf = e.cpf) "
+ " WHERE e.cpf=cpf)")
private SectorDTO sector;
可以用 @PostLoad
用法来完成。
@Formula(value = "(SELECT concat(s.cod_setor, '_', s.descricao_setor)"
+ " FROM service.sector s LEFT JOIN service.employee e "
+ " ON (s.cpf = e.cpf) "
+ " WHERE e.cpf=cpf)")
// select multiple fields as one string where values are divided by '_'
private String sectorFormula;
@Transient
private SectorDTO sector;
@PostLoad
private void onLoad() {
String[] parts = sectorFormula.split("_");
this.sector = new SectorDTO(parts[0], parts[1]);
}