对具有计算字段的实体进行分页查询

Paged query on entity with calculated field

我有一个视图的分页查询,其中一个字段用 @Formula 注释(使用 ajahe ebean 查询)。

当 运行 对 page > 0 的查询时,我得到一个错误:

PersistenceException: Query threw SQLException:No column name was specified for column 8 of 'limitresult'.

生成的查询是:

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 解决了问题,但是我不知道如何让框架添加别名以使查询正常工作。

谢谢

解决方案是为公式定义添加一个别名: 代替 @Formula(select = "total_inventory - total_fulfilled - total_not_for_sale")

改为 @Formula(select = "total_inventory - total_fulfilled - total_not_for_sale as totalAvailable")