2016-02-29 87 views
0

我只是尋找我的場景下面描述與春季數據JPA和查詢DSL的想法。 我想將以下語句QueryDsl - 集合表達式中的動態子查詢

select * from document doc1 
where doc1.name = <name> and doc1.date in (
(select max(doc2.date) from document doc2 where doc2.type = <type2>) , 
(select max(doc3.date) from document doc3 where doc3.type = <type3>)) 

轉換成查詢DSL。 「Name」和「type1」..「typen」作爲params傳遞。正如你所看到的,查詢應該得到特定類型文檔的最大值(日期)。 預先感謝您。

回答

0

下應該工作

query.select(doc1).from(doc1) 
    .where(doc1.date.in(
     subquery.select(doc2.date.max()) 
       .from(doc2).where(doc2.type.in(...))) 
    .fetch() 
+0

嗨蒂莫,感謝您的答覆。我無法解決我的問題。我期待這樣的事情:query.from(DOC1) 。凡(doc1.name.eq(參數1)) 。凡(doc1.date.in(, \t \t \t \t \t \t \t \t 的唯一輸出)) – Baya