gpt4 book ai didi

java - Hibernate 更改 @Formula 中的别名

转载 作者:行者123 更新时间:2023-12-02 13:30:37 24 4
gpt4 key购买 nike

我有一个字段:

@Formula(value = "(select max(crm_kk_rejestr.data_otrzymania) " +
"from crm_kk_rejestr " +
"where crm_kk_rejestr.idkntrh = idkntrh)")
private Date dataOtrzymania;

我想按此字段排序,但出现错误:

ORDER BY column or expression must be in SELECT list in this context.

最佳答案

有一个解决方案(SQL Server),例如:

private String yourFieldForAlias;

@Formula("( validSQLquery ) as 'yourOwnAlias', NULL")
public String getYourFieldForAlias() {
return yourFieldForAlias;
}

生成的查询将是:

....
( validSQLquery ) as 'yourOwnAlias', null as formula0_0_
....

你只需要:

order by yourOwnAlias

关于java - Hibernate 更改 @Formula 中的别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43204769/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com