我在一个视图上有一个分页查询,其中一个字段与@Formula
相关联(使用ajahe ebean查询)。
在page > 0
上运行查询时出现错误:
PersistenceException:Query抛出SQLException:没有为'limitresult'的第8列指定列名。
生成的查询是:
select *
from (
select top 20 row_number() over (order by product_id) as rn,
t0.product_id c0, t0.isbn c1,
t0.provider_external_id c2,
t0.total_inventory c3,
t0.total_fulfilled c4,
t0.total_not_for_sale c5,
total_inventory - total_fulfilled - total_not_for_sale
from product_stock_status t0
order by product_id
)
as limitresult where rn > 10 and rn <= 20 .
直接在数据库(mssql)上运行此查询会导致相同的异常。
为生成的值total_inventory - total_fulfilled - total_not_for_sale
添加别名可以解决问题,但是我不知道如何让框架添加别名以使查询起作用。
由于
答案 0 :(得分:0)
解决方案是在公式定义中添加别名: 代替 @Formula(select =&#34; total_inventory - total_fulfilled - total_not_for_sale&#34;)
更改为 @Formula(select =&#34; total_inventory - total_fulfilled - total_not_for_sale as totalAvailable&#34;)