是否可以使用 @Formula 注釋檢索自定義物件?我想在我的一個物體中檢索特定表的代碼和描述:
@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;
uj5u.com熱心網友回復:
它可以通過@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]);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/438887.html
