How can I replace using Query by Example in Spring Data JDBC?

627 Views Asked by At

In my view I send async request to controller with Json Data as following:

{
   "filters":{
      "someField":"someValue",
      "someField":"someValue",
      "someField":null,
      "someField":null,
   }
}

But data can be different. And I have Order Entity that has same fields, so I can convert It from Json to POJO

After that using JPA I can do following:

Example<Order> orderExample = Example.of(orderFromJson);
orderRepository.findAll(orderExample);

But I use spring-data-jdbc which doesn't support it, What can replace it?

1

There are 1 best solutions below

0
Jens Schauder On

For cases like this where no direct support is offered, the correct approach is to get a JdbcTemplate or NamedParameterJdbcTemplate injected, and construct the required SQL from your filter information. You may make the method a custom repository method.