In my @Repository interface I created custom find method with JPQL @Query that contains parameter (addressType).
from Address a where a.addressType = :addressT
In Java 8, you can use reflection to access names of parameters of methods. This makes the @Param
annotation unnecessary, since Spring can deduce the name of the JPQL parameter from the name of the method parameter.
But you need to use the -parameters
flag with the compiler to have that information available.
See http://docs.oracle.com/javase/tutorial/reflect/member/methodparameterreflection.html.
Answer from JB Nizet and Xtreme Biker are both corrects. I just want to add that if you use Spring Boot the -parameters
compiler flag is already added for you by spring-boot-starter-parent (Gradle or Maven) :
plugin {
delegate.groupId('org.apache.maven.plugins')
delegate.artifactId('maven-compiler-plugin')
configuration {
delegate.parameters('true')
}
}
The answer given by @JB Nizet is correct, but I just wanted to point out the way to add the -parameters
flag for the Java 8 compiler when using Eclipse. This is in Window -> Preferences:
Maven also allows adding the flags in the pom itself:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<compilerArgs>
<arg>-verbose</arg>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
To add parameters flag for Java 8 compiler when using IDEA IntelliJ
File > Settings > Build, Execution, Deployment > Compiler > Java Compiler