hibernate条件查询选择更新顺序

时间:2014-05-02 20:37:11

标签: hibernate criteria hibernate-criteria

我有以下使用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();

它生成以下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

结果是

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."

我有两个表ACT.EVENT(父)和ACT.PERSON_EVENT(子)使用hibernate表建模,每个子类继承具有一对一的关系。因此实体类PersonEvent扩展了抽象实体类Event。

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

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

如何使用Criteria API编写与订单相同的查询。

0 个答案:

没有答案