在这个hibernate pojo中,@ Formula在运行时不适用于PAIS_CD参数:
@Entity
@Table(name = "PAISES")
public class Pais {
@Id
@Column(name = "PAIS_CD", unique = true, nullable = false, precision = 3, scale = 0)
private Integer codigo;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "pais", orphanRemoval = true)
@OrderBy("dtInicioVigencia desc")
private List<NomePais> nomesPais = new ArrayList<NomePais>(0);
@Formula(value = "(select nmps_nm from ( select nmps_nm, nmps_dt_inicio, nmps_dt_fim," +
"(case when TRUNC(current_date) between np.NMPS_DT_INICIO and COALESCE(np.NMPS_DT_FIM, TO_DATE('01/01/9999')) THEN 0 " +
"when ABS(TRUNC(CURRENT_DATE) - np.NMPS_DT_INICIO) > ABS(TRUNC(CURRENT_DATE) - COALESCE(np.NMPS_DT_FIM, TO_DATE('02/01/0001'))) " +
"THEN ABS(TRUNC(CURRENT_DATE) - COALESCE(np.NMPS_DT_FIM, TO_DATE('02/01/0001'))) " +
"ELSE ABS(TRUNC(CURRENT_DATE) - np.NMPS_DT_INICIO) end) " +
"from nome_paises np where np.NMPS_PAIS_CD = PAIS_CD " +
"order by 4, np.NMPS_DT_INICIO desc " +
") where ROWNUM = 1)")
@Transient
private String nomePaisVigente;
...
}
我怀疑Hibernate不支持@Formula中的第三级子选择。针对这种情况的一些解决方案?
使用hibernate-core:3.5.1-Final和hibernate-jpa-2.0-api:1.0.0-Final
答案 0 :(得分:1)
hibernate会忽略使用@Transient注释的字段。请尝试删除@Transient
答案 1 :(得分:0)
生成hibernate查询。问题是无法识别PAIS_CD参数。