0

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

Injection
  • 301
  • 3
  • 8

1 Answers1

1

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.

  • Yes, you were right, as soon as I converted everything int to Long everything worked. thank you very much – Injection Aug 30 '19 at 06:08