JPA Speciffication - Filter entity list

Asked

Viewed 29 times

-2

I have a "Request" entity with a task list (another entity) and need to use speciffication to filter the requested entity and the nested task list.

Example: Select * Order where tarrefa.finalizada = "S"

I need to return a list of orders and tasks that have been performed.

My problem is the nested list, specffication filters the only entity Request and not the task list.

Code:

`

public static Specification<UsuarioProcesso> porFinalzada(Indicador finalizada){
       return new JoinableSpecification<>() {
            @Override
            public Predicate toPredicate(Root<UsuarioProcesso> root, CriteriaQuery<?> cq, CriteriaBuilder cb) {
                Path<Indicador> path = this.joinList(root, UsuarioProcesso_.tarefas, JoinType.INNER).get(UsuarioProcessoTarefa_.finalizada);
                return cb.equal(path, finalizada);
            }
        };
    }

`

1 answer

-4


I found the solution.

Use "root.fetch"

fetch will force JPA to perform the query that fetches the tasks along with the query that fetches the requests, so the two will pass through the filter

Browser other questions tagged

You are not signed in. Login or sign up in order to post.