0

I have a below HQL query

"select distinct p from Participant p left join fetch p.basketItemViewStates as bi where p.basket.id = ?1 order by p.lastName"

where Participant has child list of BasketItemViewStates and BasketItemViewStates further have a child with one to one relationship called

   @OneToOne(cascade = CascadeType.MERGE)
    private BasketItem basketItem;

BasketItem has sortOrder as a column, i want that list which is fetched in join, should be sorted on the basis of that sortOrder.

Can anyone explain, how i can do it in above query

4

1 に答える 1

0

, bi.sortOrderhqlリクエストの最後に追加でき ます:

select distinct p from Participant p left join fetch p.basketItemViewStates as bi where p.basket.id = ?1 order by p.lastName, bi.sortOrder

子のsortedCollectionを使用Comparableして、子エンティティにインターフェイスを実装し、このコレクションを自然な順序で並べ替えて休止状態にするように指定することもできます。

[編集]あなたの質問を編集した後、私はこのようなものがうまくいくはずだと思います:

select distinct p from Participant p left join fetch p.basketItemViewStates as bi left join bi.basketItem as bitem where p.basket.id = ?1 order by p.lastName, bitem.sortOrder
于 2013-03-19T12:38:59.703 に答える