Исправить allogalargumentException для параметров в JPAJAVA

Программисты JAVA общаются здесь
Anonymous
Исправить allogalargumentException для параметров в JPA

Сообщение Anonymous »

В JPA я пытаюсь искать таблицу с двумя дополнительными полями, скажем, один и два, которые могут быть нулевыми иногда. У меня есть контроллер и репо, как ниже. < /P>
class Some{
private SomeRepo someRepo;

public Stops(SomeRepo someRepo) {
this.someRepo = someRepo;
}

@GetMapping("/some")
public ResponseEntity fetchData(
@RequestParam(value="code", required=false) Integer one,
@RequestParam(value="name", required=false) String two
) {

Iterable some;

some = this.someRepo.findByOneLikeAndTwoLikeIgnoreCaseOrderByOneAsc(one, two);
return ResponseEntity.ok(some);

}
< /code>
public interface SomeRepo extends CrudRepository {

Iterable findByOneLikeAndTwoLikeIgnoreCaseOrderByOneAsc(@Nullable Integer one, @Nullable String two);
}
< /code>
When I make a GET call with only one param like below, I am getting the below error, which should not be the case as I am using @Nullable for the method in the SomeRepo.
curl -X GET $HOST:$PORT/some?name=West

2025-07-29T12:34:54.396-07:00 ERROR 1802042 --- [nio-8080-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet] :
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
[Request processing failed: java.lang.IllegalArgumentException:
Value of parameter with name one must not be null] with root cause at org.springframework.data.relational.repository.query.ParameterMetadataProvider.checkNullIsAllowed(ParameterMetadataProvider.java:123) ~[spring-data-relational-3.1.0.jar:3.1.0]
at org.springframework.data.relational.repository.query.ParameterMetadataProvider.next(ParameterMetadataProvider.java:88) ~[spring-data-relational-3.1.0.jar:3.1.0]
at org.springframework.data.relational.repository.query.CriteriaFactory.createCriteria(CriteriaFactory.java:109) ~[spring-data-relational-3.1.0.jar:3.1.0]



Подробнее здесь: https://stackoverflow.com/questions/797 ... ams-in-jpa

Вернуться в «JAVA»