Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dschulten opened this issue Jan 31, 2025 · 1 comment
Assignees
Labels
type: bug A general bug

Comments

@dschulten
Copy link

dschulten commented Jan 31, 2025

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?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 31, 2025
@mp911de
Copy link
Member

mp911de commented Jan 31, 2025

Example works on properties (and nested property paths). Embedding is merely a way to represent values in the table while the logical model should not care about embedding. I consider this a bug.

@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants