0

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.

Bahman Parsa Manesh
  • 2,314
  • 3
  • 16
  • 32
amit kumar
  • 121
  • 1
  • 10
  • Are you sure that was it overridden? Maybe it happened because of the INNER join. Also, pls include the class file of the entity you want to get. – Selindek Mar 12 '19 at 16:17
  • @Selindek yes the query showing only inner join. although i have change root.fetch to root.join and its works but i got org.springframework.orm.jpa.JpaSystemException: More than one row with the given identifier was found error – amit kumar Mar 13 '19 at 15:15
  • pls add the entity sources to the question. – Selindek Mar 13 '19 at 18:41
  • i have uploaded another question on the same issue. please check following link:- https://stackoverflow.com/questions/55158314/its-works-but-i-got-org-springframework-orm-jpa-jpasystemexception-more-than-on – amit kumar Mar 14 '19 at 08:52
  • @ Selindek- when i use root.join, from select it removes all the columns of the right hand side tables. – amit kumar Mar 14 '19 at 10:34

0 Answers0