Last active
January 4, 2016 18:59
-
-
Save oak-tree/8664118 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (keywords.size() > 0) { | |
SetJoin<Report, Keyword> keyword = report.join(Report_.keywords); | |
Expression<Long> keywordExpr = keyword.get(Keyword_.id); | |
Predicate pred = keywordExpr.in(keywords); | |
preds.add(pred); | |
query.having(cb.equal(cb.countDistinct(keyword.get(Keyword_.id)), | |
keywords.size())); | |
} | |
if (tribes.size() > 0) { | |
SetJoin<Report, Tribe> item = report.join(Report_.tribes); | |
Expression<Long> itemExpr = item.get(Tribe_.id); | |
Predicate pred = itemExpr.in(tribes); | |
preds.add(pred); | |
query.having(cb.equal(cb.countDistinct(item.get(Tribe_.id)), | |
tribes.size())); | |
} | |
if (periods.size() > 0) { | |
SetJoin<Report, Period> item = report.join(Report_.periods); | |
Expression<Long> itemExpr = item.get(Period_.id); | |
Predicate pred = itemExpr.in(periods); | |
preds.add(pred); | |
query.having(cb.equal(cb.countDistinct(item.get(Period_.id)), | |
periods.size())); | |
} | |
query.where(cb.and(preds.toArray(new Predicate[preds.size()]))) | |
.groupBy(report.get(Report_.id)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if only one field is involved this result are ok. but when there are more than 1 field. i.e tribes and periods as well. the search can give on some input wrong results