I am testing Spring-Data-JPA with Spring-Boot, using hibernate-core 5.4.2.Final version.
For example, I have a Users
table containing address and other columns.
My repository interface for this table is as below.
public interface UsersRepository extends JpaRepository<Users, Integer> {
List<Users> findByAddressContaining(String keyword)
}
To my knowledge, if I name the method like I did, the query below will be executed.
SELECT * FROM Users u WHERE address LIKE '%keyword%';
The problem is, this partly works.
For example, there are two datas in users
table, each datas having address of "abc" and "cde".
If i test the findByAddressContaing("abc")
, the result size of List<>
is 2.
Right after if I run findByAddressContaining("de")
, the result should be 1, but it is 2.
If i run the same method findByAddressContaining("de")
again, then the result becomes 1.
I can't find the way to solve this problem. Any suggestions would be helpful. :)
THE PROBLEM WAS NOT WITH THE Spring-Data-JPA, it was with Request Parameter.
This is my controller method.
@GetMapping("/v2/warehouses")
public void getAllWarehouses(@RequestParam(name = "address") String address,
@RequestParam(name = "limit") Integer limit,
@RequestParam(name = "offset") Integer offset,
HttpServletResponse response) {
System.err.println("Request Param Address : " + address");
If I send request to the correct path using Postman, sometimes address comes as blank.("")
Does this happen normally??