2015-10-15 35 views
0

我在集合上使用querydsl。 我想要获取包含在另一个列表中的所有元素。querydsl over集合在子句中

public class Parent { 
    private List<Child>; 
} 

public class Child { 
    private String key; 
    private String value; 
} 

由于子对象的具体名单(List<Child> lovedChilds),对于每一个家长,我需要选择那些孩子的都包括在lovedChilds

List<Parent> parents = ...; 
for (Parent parent in parents) 
{ 
    select 
     from (child, parent.childs) 
     where lovedChilds contains a lovedChild 
     where child.getKey.equals(lovedChild.getKey); 
} 

回答

0

既然你有一个N:M关系你应该有一个交叉表的地方。 我假定它是parent2child与列parentchild(外键到相应的ID列)。

简单地执行联接:

select * from parent join parent2child join child where child.key in lovedChildren 

如果你想要得到的父对象只有一次,你可以添加一个group bydistinct