基于子实体的属性值搜索实体的JPA标准?(重复联接)



我有以下查询,它正确地返回了一个基于标签(子(值的标记(父/根实体(,但是,它在响应中复制了父实体17次(因为它有17个标签(。你知道我在这里做错了什么吗?

builder.and(
builder.equal(root.join("labels").join("labelIdentity").get("key"), "owner"),
builder.like(root.join("labels").get("value"), "bob")
);

更新

我尝试了以下基于https://issues.apache.org/jira/browse/OPENJPA-2333但这仍然返回了17个重复的结果,而只有一个应该返回:

final Join labels = root.join("labels", JoinType.INNER);
final Join labelIdentities = labels.join("labelIdentity", JoinType.INNER);
builder.and(
builder.equal(labelIdentities.get("key"), "owner"),
builder.like(labels.get("value"), "bob")
);

基于这个公认的答案,我相信使用query.distinct(true)将消除重复,并且似乎是推荐的方法:https://stackoverflow.com/a/11257160/12177456

问题可能出在JPA的操作方式上。以下页面可能会有所帮助:https://issues.apache.org/jira/browse/OPENJPA-2333

(我会评论,但没有足够的信誉点…(

最新更新