0

HQL を介して次のクエリを実行しようとしていますが、スタックしており、このクエリは結果を表示していません。

select s from Serie s where
(s.arrivalSerie is not null and s.arrivalSerie.company.isEnable=1)
or (s.departureSerie is not null and s.departureSerie.company.isEnable=1)

このクエリを次のようにスローしています。

Query query = em.createQuery("previous query");
query.setFirstResult(initialElement);

このクエリをテストしているときに、このクエリの任意の部分 (「または」) を結果で実行できることがわかりました。しかし、クエリ全体が実行されると、0 要素のコレクションが得られます。

何か案は?

アップデート:

理解しやすい翻訳されたクエリは次のようになります。

select
        s.*
    from
        serie s,
        arrivalSerie a,
        company ca,
        departureSerie d,
        company cd 
    where
        s.idArrivalSerie=a.idArrivalSerie 
        and a.CompanyCode=ca.CompanyCode 
        and s.idDepartureSerie=d.idDepartureSerie 
        and d.CompanyCode=cd.CompanyCode 
        and (
            (
                s.idArrivalSerie is not null
            ) 
            and ca.isEnable=1 
            or (
                s.idDepartureSerie is not null
            ) 
            and cd.isEnable=1
        ) limit 0,10;

もちろん、これは MySql クライアントでの結果を示しているわけではありません

4

1 に答える 1

0
s.arrivalSerie.company

との間に内部結合を作成し、 と の間Serieに別ArrivalSerieの内部結合を作成します。また、内部結合は、null のarrivalSerie を持つすべてのシリーズを除外しますが、これは明らかに望んでいるものではありません。したがって、代わりに左結合を使用する必要があります。ArrivalSerieCompany

select s from Serie s 
left join s.arrivalSerie arrivalSerie
left join arrivalSerie.company arrivalCompany
left join s.departureSerie departureSerie
left join departureSerie.company departureCompany
where arrivalCompany.isEnable = 1 or departureCompany.isEnable = 1
于 2013-10-23T08:37:03.637 に答える