Home > other >  How to write the following sql query with CriteriaBuilder
How to write the following sql query with CriteriaBuilder

Time:03-05

I have problem while I want to write query into Criteria Builder. Or if is better to compose SQL query to be easyer to write in criteria builder ?

select
    DATA_TABLE.*, M_ORDER.CODE 
from
    ( select
        log0_.MSG_ID,
        login1_.NAME,
        log0_.METHOD,
        logpa2_.VALUE
    from
        M_LOG log0_
    inner join
        M_LOG_INTER login1_ 
            on log0_.ID_INTER=login1_.ID_INTER 
    inner join
        M_PARAMS logpa2_ 
            on log0_.MS_ID=logpa2_.MS_ID 
    where
        logpa2_.KEY='id'
    ) DATA_TABLE, M_ORDER
WHERE
    data.value = m_order.ID and
    rownum <= 10; 

CodePudding user response:

Restructured (simplified) SQL query:

select
    * 
from
    ( select
        log0_.MSG_ID,
        login1_.NAME,
        order3_.CODE,
        log0_.METHOD
        logpa2_.VALUE,
    from
        M_LOG log0_,
        M_LOG_INTER login1_,
        M_LOG_PARAMS logpa2_,
        M_ORDER order3_ 
    where
        logpa2_.KEY='id' 
        and logpa2_.VALUE=order3_.ID 
        and log0_.MS_ID=logpa2_.MS_ID 
        and log0_.ID_INTER=login1_.ID_INTER
    ) 
where
    rownum <= 10;

And query with CriteriaBuilder was easly.

  • Related