JPA Jakarta Criteria Specification API. Issue with getting distinct column with other columns

52 Views Asked by At

I am having criteria api implemented for search filters, Now there is one filter which needs to filter ids which are not part of particular group. Now issue is the table which hold this data is having duplicate ids. I currently have subquery defined which returns ids which are part of the group and i am using not in clause to filter ids. but it is returning duplicate ids as well. Below is reference code inside toPredicate() method.

Join<TableA, TableAEmbeddedKey> tableIdJoin = root.join(TableA_.ID);
Subquery<String> subquery = query.subquery(String.class);
Root<TableA> rootSubquery = subquery.from(TableA.class);
Join<TableA, TableAEmbeddedKey> joinAId = rootSubquery.join(TableA_.ID);
subquery.select(joinAId.get(TableAEmbeddedKey_.id));
subquery.where(criteriaBuilder.equal(joinAId.get(TableAEmbeddedKey_.grpId), this.grpId));
predicates.add(criteriaBuilder.in(tableIdJoin.get(TableAEmbeddedKey_.ID)).value(subquery).not());

How do i modify this to have unique Ids regardless of other column unique or not. There are some few other columns.

0

There are 0 best solutions below