When spring starts without Example
everything is fine, but with Example
the result is empty
Application.java
@SpringBootApplication
public class SelkinApplication {
public static void main(String[] args) {
SpringApplication.run(SelkinApplication.class, args);
}
}
SvHistoryRep.java
public interface SvHistoryRep extends CrudRepository<SvHistory, Integer>, QueryByExampleExecutor<SvHistory> {
}
Service.java
@PostMapping(path = "getFilteredHistory")
public @ResponseBody void getFilteredHistory(@RequestBody SvHistory svHistory){
SvHistory history = new SvHistory();
history.setJobStatusId(1);
Example<SvHistory> example = Example.of(history);
svHistoryRep.findAll(example).forEach(System.out::println);
}
When without Example, it's work. svHistoryRep.findAll().forEach(System.out::println);
But with Example, i have empty result
My Guess: SvHistory
has some values, that are initialized with default values. So there is an equality check not only on the id
column.
To check this, log your example object. If there are any non null values and they are not equal to the searched object, you'll see the bug. Very probably the reason is auto initialized primitive types like int, boolean etc.