Answer the question
In order to leave comments, you need to log in
How to build an Entity from two tables with a sheet filter?
Can anyone suggest how this can be done? Right now I have a @Repository which is
extends JpaRepository, JpaSpecificationExecutor. Specification I need to perform various filters.
public static Specification<Entity> entityWithSpecification(List<Long> ids, Date startDate, List<String> books) {
return (root, query, builder) -> {
ArrayList<Predicate> predicates = new ArrayList<>();
if (startDate != null) predicates.add(builder.greaterThanOrEqualTo(root.get("date").as(Date.class), startDate));
if (ids != null) predicates.add(root.<Long>get("id").in(ids));
if (books != null) predicates.add(root.<Stocks>get("book").as(String.class).in(books));
return builder.and(predicates.toArray(new Predicate[predicates.size()]));
};
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question