I have the following query, which is correctly returning a tag (parent/root entity) based on the label (children) value, however, it is duplicating the parent entity 17 times (because it has 17 labels) in the response. Any ideas what I'm doing wrong here?
builder.and(
builder.equal(root.join("labels").join("labelIdentity").get("key"), "owner"),
builder.like(root.join("labels").get("value"), "bob")
);
Update
I have tried the following based on https://issues.apache.org/jira/browse/OPENJPA-2333 but this is still returning 17 duplicate results, when only one should be returned:
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")
);
I believe using query.distinct(true)
will get rid of the duplicates and seems to be the recommended approach, based on this accepted answer: https://stackoverflow.com/a/11257160/12177456