实体类中有Set<Tag>集合。Tag类只包含Long id和String值。我试图通过Place找到Tag,但我得到了错误Could not analyze lambda code
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()的东西
发布于 2015-09-08 18:27:24
我不熟悉您的模式,但也许您可以通过这样的方法来连接您的数据结构:
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但是,如果不能使用join,则可以尝试使用子查询,但是子查询在不同的JPA提供程序上表现得有点精细。对于子查询,只需确保子查询与普通查询的格式相同。
stream = stream
.where(p -> JinqStream.from(p.getTags())
.where( tag -> tag.getName().equals(name) )
.count() > 0);https://stackoverflow.com/questions/32440691
复制相似问题