hibernate criteria query select for update order by

≯℡__Kan透↙ 提交于 2019-12-11 01:38:36

问题


I have the following code that uses Hibernate Criteria API.

    List<?> results = getCurrentSession()
            .createCriteria(PersonEvent.class)
            .add(Restrictions.eq(STATUS, EventStatus.NEW))
            .addOrder( Order.asc("sequence") )
           .setLockMode(LockMode.PESSIMISTIC_WRITE)
            .setMaxResults(maxResults).list();

It generates the following sql

select
        * 
    from
        ( /* criteria query */ select
            this_.SEQUENCE as SEQUENCE0_0_,
            this_1_.CREATED_UTC as CREATED3_0_0_,
            this_1_.UPDATED_UTC as UPDATED5_0_0_,
            this_1_.STATUS as STATUS0_0_,
            this_.PERSONID as PERSONID1_0_ 
        from
            ACT.PERSON_EVENT this_ 
        inner join
            ACT.EVENT this_1_ 
                on this_.SEQUENCE=this_1_.SEQUENCE 
        where
            this_1_.STATUS='NEW' 
            order by this_1_.SEQUENCE) 
    where
        rownum <= 50 for update

Which results in

ORA-02014: cannot select FOR UPDATE from view with DISTINCT, GROUP BY, etc.
02014. 00000 -  "cannot select FOR UPDATE from view with DISTINCT, GROUP BY, etc."

I have two tables ACT.EVENT (parent) and ACT.PERSON_EVENT (child) modeled using hibernate table per subclass inheritance with one-one relationship. So entity class PersonEvent extends abstract entity class Event.

ACT.EVENT
-SEQUENCE (PK)
-STATUS
-CREATED_UTC
-UPDATED_UTC

ACT.PERSON_EVENT
-SEQUENCE (PK, FK)
-PERSONID

How can I write this same query with order by using Criteria API.

来源:https://stackoverflow.com/questions/23436546/hibernate-criteria-query-select-for-update-order-by

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!