0

dears.

Currently, I am working with JpaSpecificationExecutor API, cause I need to create dynamic queries based on a lot of optional search criteria, for this I am starting with a root entity, which is included in the generic type in the JpaSpecificationExecutor interface.

The code to make the build in the Specification (which is included in the findAll method that belongs to repository interface) is the following:

    public Specification<T> build(){
            return (root, query, criteriaBuilder) -> {
                Predicate filters = null;
                
//createPredicate is a method to create predicates (it does not matter in this code)

                filters = createPredicate(root, criteriaBuilder, searchCriterias);              
                return filters;
            };
        }

Now each is working fine, but there is a little detail, in the query I am using joins to make relation with other entities, but when I get the response, like in this code:

List<EXAMPLE> examples = repository.findAll(filters.build());

I am not able to see the filter data in other entities, just I can see the field in the root entity (It is EXAMPLE entity) because these ones are appearing in the query formed. so, I would like to include in the SELECT the other entities, in order to see the filter data by means of the JOINs, but until now I have not been able to do it.

I have seen in any inputs, that I can use these codes in my build code, I have tried, but the new files are not appearing in the generated query:

query.select, or query.multiselect

Ref: Ref. 1

Also, I have found that this is not working with JpaSpecificationExecutor, because the list of attributes in the SELECT is assigned by the entity Ref. 2

My question is, does someone know if exists another way to change the field in the SELECT with JpaSpecificationExecutor.

Regards.

J. Abel
  • 790
  • 1
  • 15
  • 31

0 Answers0