ColdFusion Form,Hibernate-检索一对多字段的最新记录

ColdFusion Form,Hibernate-检索一对多字段的最新记录,hibernate,orm,coldfusion,Hibernate,Orm,Coldfusion,我在持久cfc中有一个自定义属性,如下所示: property name="last_live_request" fieldtype="one-to-many" cfc="Accreditation" fkcolumn="pers_ky" setter="false" orderby="ACCR_KY desc" where="status_doma_ky in (27,28) an

我在持久cfc中有一个自定义属性,如下所示:

property    name="last_live_request" 
        fieldtype="one-to-many" 
        cfc="Accreditation" 
        fkcolumn="pers_ky" 
        setter="false" 
        orderby="ACCR_KY desc" 
        where="status_doma_ky in (27,28) and rownum = 1"
;
其目的是加入一对多的认证记录,并仅检索最近的一个。问题是它不起作用

与普通的PL_SQL一样,rownum在排序之前被计算,因此我没有得到最新的记录

普通PL-SQL中的解决方案是执行如下子选择,以便我们首先获取记录,然后选择顶部记录:

    select *
    from (
        select *
        from JOU_V_REV_PEACC 
        where status_doma_ky in (27,28)
        and pers_ky = [nnn]
        order by ACCR_KY desc
    )
    where rownum = 1
所以我的问题是,我如何在我的cfc财产中实现这个结果

我找到了一个解决办法:

// Get the max id using the formula attribute (note, requires SQL, not HQL)
property name="LAST_LIVE_ACCR_KY" setter="false" formula="
    select max(peac.accr_ky)
    from JOU_V_REV_PEACC peac
    where peac.status_doma_ky in (27,28)
    and peac.pers_ky = PERS_KY
";

// Set up the property
property name="last_live_request" persistent="false" default="";

// Load the required Accreditation using a custom function
function getlast_live_request() {
    return entityLoadByPK("Accreditation", this.attr('LAST_LIVE_ACCR_KY'));
}
不是很漂亮,但很有效