Grails 2.5.1 (hibernate 3) criteria multiple joins to same table

て烟熏妆下的殇ゞ 提交于 2019-12-02 11:26:54

Unsure why you need multiple joins to same table ? if question is understood correctly

String query="from someDomain sd join productData pd where pd.type in (:types) and pd.value in (:values) "
def inputParams=[:]
inputParams.values=['GC','P1']
inputParams.types=[4,5]
List resultsList = SomeDomain.executeQuery(query,inputParams,[readOnly:true,timeout:15])

pd.type may have to be another join since in the debug it attempts to get the .id so add another join

  String query="from someDomain sd join productData pd join pd.types tp where tp.id in (:types) and pd.value in (:values) "

If you wanted to do multiple joins as suggested in the question

  String query="from someDomain sd join productData pd join pd.types tp, ProductData pd2 where tp.id in (:types) and pd.value in (:values) and pd2.something=pd.something"

That is then going off and looking productData that is linked to someDomain then again looking up entire ProductData as pd2 and then confirming where pd2.something = pd.something

Using comma's in HQL becomes a new lookup not related to existing query..

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!