2013-03-20 40 views
1

我有一個實體編碼器有0-n喜歡。 我的查詢包括,給一個名叫編碼器中,在尋找具有共同的至少一個順心的所有編碼器,通過降與A.這裏共同喜好的計數開的是什麼樣子至今:QueryDSL休眠:通過交點排序

query.from(coder, other) 
    .where(
      coder.firstName.toLowerCase().eq(firstName) 
      .and(coder.lastName.toLowerCase().eq(lastName)) 
      .and(other.ne(coder)) 
      .and(other.likings.any().in(coder.likings)) 
    ) 
    .orderBy(coder.likings.???); 

是有一種方法可以通過QueryDSL實現指定custon命令嗎?我在ListPath找不到任何相關內容。如果是這樣,我可以使用番石榴計算交集。

由於提前,

羅爾夫

回答

1

你可以嘗試

.orderBy(coder.likings.size().desc()); 

如果不行嘗試通過明確的聚集額外的連接和組。

+0

感謝您的回答。 我真的想要做些什麼: .orderBy(intersection(coder.likings,other.likings).size()) – Rolf 2013-03-20 22:59:56

+0

我想你可以通過連接和groupBy來表達。 – 2013-03-21 07:39:01