spring-projects / spring-projects/spring-data-relational

JDBC: QBE withIgnoreNullValues does not ignore nulls in embedded classes of the Example

Open
#1,986 3 comments 0 reactions 1 assignee View on GitHub

@schauder is already working on this.

Since Jan 31, 2025.

type: bug
Dominant language
Java
Stars
827
Forks
394
PR merge metrics
No merged PRs in 30d

Description

I have an example Spring Data Jdbc Aggregate Root (not JPA)

@RequiredArgsConstructor(access = AccessLevel.PACKAGE, onConstructor = @__(@PersistenceCreator))
public class Person implements AggregateRoot<Person, PersonIdentifier> {

   @Id private final PersonIdentifier id
   
    private String name;
    
    @Getter
    @Embedded 
    private Address address;
}

with an embedded VO record:

public record Address(String city, String street} implements ValueObject

When I have three people, two persons who live in streets of Heilbronn and one Person who lives in a street of Berlin, and I run this qbe Query on my QueryByExampleExecutor:

personRepository.findAll(
        Example.of(
            person,
            ExampleMatcher.matching().withIgnorePaths("id").withIgnoreNullValues()));

with this Person:

{
	"address": {		
		"city": "Heilbronn"
	}
}

I get no matches, because the generated query specifically asks for Persons with STREET = null. That only happens for embedded types - the generated query does not ask for persons where NAME == null, apparently because name is a top-level attribute. Log extract:

WHERE (("PERSON"."CITY" = ? AND "PERSON"."STREET" = ?))
Setting SQL statement parameter value: column index 1, parameter value [Heilbronn], value class [java.lang.String], SQL type 12
Setting SQL statement parameter value: column index 2, parameter value [null], value class [null], SQL type 12

I would expect two matches, all persons who live in Heilbronn.

Am I holding it wrong, or is ignoreNullValues simply not supported for embedded types?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.