'JAVA JPA Containing Hibernate long search is not working
Hi I am trying to do a search based on name mobile number and id Here : id is in string name is in string
if queried with both works fine but for the same when i search with mobile number(Long) throws an error
"org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [%9%] did not match expected type [java.lang.Long (n/a)];
my code as follows
controller
@GetMapping("searching")
public ResponseEntity<Response> searching(@RequestParam("Id") final String Id,
@RequestParam("name") final String name,
@RequestParam("phoneNumber") final Long phoneNumber,
HttpSession session) {
response = new Response();
try {
List<UserDTO> data = userService.searching(Id, name, phoneNumber );
if (!data.isEmpty()) {
response.setMessage(StringConstance.SUCCESSFUL);
response.setData(data);
} else {
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(response);
}
} catch (Exception e) {
e.printStackTrace();
throw e;
}
return ResponseEntity.status(HttpStatus.OK).body(response);
}
Service
public List<UserDTO> searching(String Id, String name,
Long phoneNumber) {
List<UserDTO> userDto = userRepository
.findByIdAndNameContainingIgnoreCaseAndPhoneNumberContaining(
Id, name, phoneNumber)
.stream().map(user -> mapToDTO(user, new UserDTO())).collect(Collectors.toList());
return userDto;
}
Repository
List<User> findByIdAndNameContainingIgnoreCaseAndPhoneNumberContaining(
Id, name, phoneNumber)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
