I am using a jpa with spring boot and I'm newbie with this. I have override
Predicate toPredicate()
of Specification. below is my code:-
public Predicate toPredicate(Root<ExportOrderInfo> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder builder) {
if(beginningOfQuarter != null && endOfQuarter != null){
criteriaQuery.distinct(true);
root.fetch("orderDetail", JoinType.LEFT);
root.fetch("orderDownload", JoinType.INNER);
return builder.and(builder.equal(root.<String>get(randomColumnName), valueToSearchFor) , builder.isNotNull(root.get("optyId")));
}else{
criteriaQuery.distinct(true);
root.fetch("orderDetail", JoinType.LEFT);
root.fetch("orderDownload", JoinType.LEFT);
return builder.and(builder.equal(root.<String>get(randomColumnName), valueToSearchFor));
}
}
When I use two root. Fetch its override the previous one. Please help me out on this.