JPA Criteria API with multiple parameters

前端 未结 5 1760
礼貌的吻别
礼貌的吻别 2020-11-30 22:39

I need to make a search method that uses the JPA Criteria API with multiple parameters. Now the problem is that not every parameter is required. So some could be null, and t

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-30 23:05

    Mikko's answer worked beautifully. Only change I needed to do, was to replace:

    cq.select(customer).where(predicates.toArray(new Predicate[]{}));

    with:

    Predicate [] predicatesarr = predicates.toArray(new Predicate[predicates.size()]); 
    cq.select(customer).where(predicatesarr);
    

    Somewhere the conversion from list to array in the original did not work.

提交回复
热议问题