0

So I'm using Gradle, Eclipse, Java 11, Spring Boot with some Spring Data JPA repositories. In Eclipse, I've tested with 3 different JDK libraries configured in the build path and in the execution: OpenJDK, OracleJDK and GraalVM. I get the same error every time: Caused by: java.lang.IllegalArgumentException: Either use @Param on all parameters except Pageable and Sort typed once, or none at all! Because of a line like:

@Query("select e from Entity e where e.value = :value")
Optional<Entity> findByValue(String value);

Guaranteed to work would be to add @Param("value") for the parameter, but I don't want to do that because this project has a lot of repositories. If I run this under the command line ./gradlew bootRun where I set one of the JDKs, this error does not occur.

If I try to reproduce this under a new project, but under Maven where I set the properties for java and maven for Java 11, then it works just fine under Eclipse.

The Gradle project works fine under a IntelliJ IDEA.

Can someone please help in explaining why this is happening? Does Eclipse bode well with Maven but not with Gradle? I can't fine an explanation.

Patrix
  • 61
  • 1
  • 6
  • Does [running Eclipse with Java 11](https://wiki.eclipse.org/Eclipse.ini#Specifying_the_JVM) fix your issue? – howlger Jul 07 '22 at 10:38
  • @howlger thanks for the response, I've ran Eclipse under all java versions (8, 11, 17) but it was not an issue. Anyway, I've figured it out and I'm preparing a detailed response for this so it can help anyone who has the same issue. – Patrix Jul 08 '22 at 12:15

1 Answers1

0

It's a compiler argument.

Seems that when the code is compiled, depending on the project, it will run with or without the -parameters argument to the javac command. When you run javac --help, the following line explains:

...
  -parameters
        Generate metadata for reflection on method parameters
...

This parameter is vital if you don't want to use @Param("value") in the repository method parameter, because this helps Spring Data determine the name of the parameter and assign it to :value.

In Eclipse(as of 2022-06), for your specific project, go to project Properties > Java Compiler and check "Store information about method parameters(usable via reflection)" and the project will work without "@Param" annotations in the repository method parameters: enter image description here

I still find it strange why on Maven projects this is activated but not on Gradle projects.

These answers helped me:

For IntelliJ IDEA, this might be a useful answer:

Patrix
  • 61
  • 1
  • 6