我无法使用joinformula选择最后一个。这些地图工作正常,但使用连接公式显示了以下错误:
来自Instrumento的外键InstrumentoData的列数错误。应该是2
@MapKeyTemporal(TemporalType.DATE)
@MapKey(name = "dataMovimento")
@OneToMany(mappedBy = "instrumento")
@LazyCollection(LazyCollectionOption.EXTRA)
private final Map<Date, InstrumentoData> instrumentoData = new HashMap<>();
@ManyToOne(fetch = FetchType.LAZY)
@JoinFormula(value = "(SELECT i.ID_INSTRUMENTO FROM InstrumentoData i WHERE i.ID_INSTRUMENTO = id ORDER BY i.data_Movimento DESC LIMIT 1)")
private InstrumentoData ultimoInstrumentoData;
有人帮我吗?
答案 0 :(得分:0)
@ManyToOne
@JoinColumnsOrFormulas({
@JoinColumnOrFormula(column = @JoinColumn(name = "id", referencedColumnName = "ID_INSTRUMENTO")),
@JoinColumnOrFormula(formula = @JoinFormula(value = "(SELECT i.data_Movimento FROM Instrumento_Data i WHERE i.ID_INSTRUMENTO = id ORDER BY i.data_Movimento FETCH FIRST 1 ROWS ONLY)", referencedColumnName = "data_Movimento"))
})
private InstrumentoData ultimoInstrumentoData;