Hibernate在DENSE_RANK Oracle数据库中添加别名

时间:2019-06-06 14:29:39

标签: oracle hibernate oracledb

我有一些类似于以下的休眠代码。

@ManyToOne(fetch = FetchType.LAZY)
@JoinFormula(value = "(SELECT MAX(status.id) KEEP (DENSE_RANK LAST ORDER BY last_update_date desc) from C_Status status WHERE status.plan_run_id = id)")

但是默认情况下,休眠状态如下所示。

(SELECT
 MAX(status.id) planrun0_.KEEP (planrun0_.DENSE_RANK planrun0_.LAST 
        ORDER BY
            planrun0_.last_update_date desc) 
        from
            C_Status status 
        WHERE
            status.plan_run_id = planrun0_.id) as formula3_ 

任何想法如何解决该问题。

下面是Hibernate的完整SQL。

select
    * 
from
    ( select
        planrun0_.id as id1_38_,
        planrun0_.created_by as created_by2_38_,
        planrun0_.creation_date as creation_date3_38_,
        planrun0_.last_updated_by as last_updated_by4_38_,
        planrun0_.last_update_date as last_update_date5_38_,
        planrun0_.last_update_login as last_update_login6_38_,
        planrun0_.version as version7_38_,
        planrun0_.tenant_id as tenant_id8_38_,
        planrun0_.plan_id as plan_id10_38_,
        planrun0_.run_type as run_type9_38_,
        (SELECT
            MAX(status.id) planrun0_.KEEP (planrun0_.DENSE_RANK planrun0_.LAST 
        ORDER BY
            planrun0_.last_update_date desc) 
        from
            C_Status status 
        WHERE
            status.plan_run_id = planrun0_.id) as formula3_ 
    from
       c_plan planrun0_ 
    where
        planrun0_.run_type=? 
        and planrun0_.tenant_id=? 
    order by
        planrun0_.id asc ) 
    where
        rownum <= ?

0 个答案:

没有答案