Query-by-example skip primitives?
Yes, you can do it:
Person p = new Person();
p.setLastName("Smith");
Example criteria = Example.create(p).setPropertySelector(
Example.NotNullOrZeroPropertySelector.INSTANCE
);
List<Person> foundPersons = session.createCriteria(Person.class).add(criteria).list();
Example.NotNullOrZeroPropertySelector.INSTANCE
is a property selector that includes only properties that are not null
and non-zero (if numeric)
UPD
Above an example for Hibernate org.hibernate.criterion.Example
class. For org.springframework.data.domain.Example
you can ignore primitive fields by manually specifying names of these fields:
Person p = new Person();
p.setLastName("Smith");
ExampleMatcher matcher = ExampleMatcher.matching().withIgnorePaths("age").withIgnoreNullValues();
Example criteria = Example.of(p, matcher);
List<Person> foundPersons = personRepository.findAll(criteria);