2015-09-07 107 views
1

我在我的实体类中收集了Set<Tag>Tag类仅包含Long idString的值。我试着去找到TagPlace但即时得到错误Could not analyze lambda code如何搜索使用Jinq设置

String name = places.getTag().getName(); 
    if (name != null) { 
     stream = stream.where(p -> p.getTags().iterator().next().getName().equals(name)); 
    } 

有办法让它紧,优雅? 我知道,我的代码是不正确的,即时得到错误,因为Jinq可能不支持这样的事情p.getTags().iterator().next().getName()

回答

1

我不熟悉你的模式,但也许你可以做一个加入扁平化你的数据结构的东西像这样:

stream 
    .joinList(p -> p.getTags()) 
    .where(pair -> pair.getTwo().getName().equals(name)); 

再次,它取决于你的数据库架构和实体,但如果你有正确的关系设置,那么你可以去更简单的东西是这样的:

tagStream 
    .where(tag -> tag.getName().equals(name)) // get the right tag 
    .selectAllList(tag -> tag.getPlaces())  // get all places with that tag 

如果尽管您不能使用连接,但您可以尝试使用子查询,但子查询在不同的JPA提供程序上表现得有点挑剔。对于子查询,只要确保子查询与普通查询的格式相同即可。

stream = stream 
    .where(p -> JinqStream.from(p.getTags()) 
     .where(tag -> tag.getName().equals(name)) 
     .count() > 0); 
相关问题