X
X
xxxxc2018-10-12 10:18:09
Spring
xxxxc, 2018-10-12 10:18:09

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()]));
    };

}

Now I need to get a new ExtendedEntity, with 2-3 additional fields from two tables. And still be able to filter. Moreover, ExtentedEntity is not a JPA @Entity and there are no links in the original Entity (@OneToMany, etc.).
In fact, all I need is 2 ordinary inner joins, but somehow get a new ExtendedEntity + filter by sheets.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question