QueryDSL BooleanExpression exclude data if the field is null

18 Views Asked by At

I have a problem when try to use a filter in a query that have a null field.

 if (StringUtils.isNotBlank(query)){
            expression = expression.and(qAdopt.name.containsIgnoreCase(query)
                    .or(qAdopt.code.containsIgnoreCase(query))
                    .or(qAdopt.specie.name.containsIgnoreCase(query))
                    .or(qAdopt.specie.code.containsIgnoreCase(query))
                    .or(qAdopt.rarity.stringValue().containsIgnoreCase(query)
                    .or(qAdopt.owner.nickName.containsIgnoreCase(query)));
        }

the values (Adopts) that not have Owner (Entity) are exclude for the response, althought the Adopt have match with the other fields (Name, code, specie.name, specie.code). I dont know why the query exclude these adopts, since the owner.nickName should been optional. If I remove the .or(qAdopt.owner.nickName.containsIgnoreCase(query))); all works correctly, but I want to filter by owner nickName.

I tried to put the validation in other places, but didn't work.

0

There are 0 best solutions below