0

I have below code to filter the data with given criteria:

public Page<Entity_DTO> findByCriteria(Entity_Criteria criteria, Pageable page) {

final Specification<Entity> specification = createSpecification(criteria);

return Page<Entity_DTO> Entity_DTOPage =
    Entity_Repo.findAll(specification, page).map(Entity_DTO_Mapper::toDTO);
}

createSpecification creates a JPA Specification based on the criteria. Now i want to add another filter, but the problem is that filter can't be added to createSpecification because i don't have a repository class for that filter as the filter is stored in a table which is managed by external library. So i can't create an Entity and Repository class for that filter. But i have access to that table using custom sql queries. So i want to know if there's a way to add a custom query(more specifically WHERE) alongside the specification variable created using createSpecification to return the filtered data. Or do i need to do away with the specification and perform filtering solely using queries? Current filters are like health, size etc. and i want to add another filter say status.

1 Answer 1

2

We can't mix a @Query definition with a Specification, so currently it's not possible to combine custom sql queries with specifications

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.