I have the following line in my @Controller
to return results based on a string or partial string passed. The string may be numerical, in which case I parse it to a long value
public @ResponseBody Page<Object> searchUsers(
@RequestParam(value = "search-string", required = false) String string) {
List<User> results = myRepo.findByUId(Long.valueOf(searchString).longValue();
//do stuff
}
My Repo Method
@Query("SELECT u FROM User b WHERE u.uid LIKE :id%")
List<User> findByIdStartsWith(@Param("uid") Long uid);
However I get the following Exception (say my parameter is "1"):
java.lang.IllegalArgumentException: Parameter value [1%] did not match expected type [java.lang.Long (n/a)]
I don't think that I'm handling this parse correctly. Any ideas?
Hibernate is trying casting the value "1%" to target type (User.id) which is Long. This is obviously impossible. LIKE works only with strings in hibernate, you may wrap with str(u.id) but see below.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With