Why are Spring Data repository method parameters names not available even on Java 8? -
i'm having hard time getting tests pass on pivotal's example project spring-boot
1.4 release from examples shows spring-data-jpa
using unannotated named parameters in jpql
e.g.
from example.springdata.jpa.simple.simpleuserrepository
@query("select u user u u.firstname = :firstname") list<user> findbyfirstname(string firstname);
nb not using @param
annotation
this doesn't run on machine. exception detailed here, self-explanatory title.
so have instead:
@query("select u user u u.firstname = ?1") list<user> findbyfirstname(string firstname);
or this:
@query("select u user u u.firstname = :firstname") list<user> findbyfirstname(@param("firstname") string firstname);
what i'm using:
- os - win7
- java - 1.8.0_112
- ide - intellij idea 2016.2
- jpa version - jpa v2.0
- configuration - spring-boot-1.4.1
so have got wrong way set examples?
did spring-data-jpa
include cool feature @ 1 time auto-detect param names reason got removed later?
org.springframework.dao.invaliddataaccessapiusageexception: name parameter binding must not null or empty! named parameters need use @param query method parameters on java versions < 8.; nested exception java.lang.illegalargumentexception: name parameter binding must not null or empty! named parameters need use @param query method parameters on java versions < 8. @ org.springframework.orm.jpa.entitymanagerfactoryutils.convertjpaaccessexceptionifpossible(entitymanagerfactoryutils.java:384) @ org.springframework.orm.jpa.vendor.hibernatejpadialect.translateexceptionifpossible(hibernatejpadialect.java:246) @ org.springframework.orm.jpa.abstractentitymanagerfactorybean.translateexceptionifpossible(abstractentitymanagerfactorybean.java:491) @ org.springframework.dao.support.chainedpersistenceexceptiontranslator.translateexceptionifpossible(chainedpersistenceexceptiontranslator.java:59) @ org.springframework.dao.support.dataaccessutils.translateifnecessary(dataaccessutils.java:213) @ org.springframework.dao.support.persistenceexceptiontranslationinterceptor.invoke(persistenceexceptiontranslationinterceptor.java:147) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:179) @ org.springframework.data.jpa.repository.support.crudmethodmetadatapostprocessor$crudmethodmetadatapopulatingmethodinterceptor.invoke(crudmethodmetadatapostprocessor.java:133) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:179) @ org.springframework.aop.interceptor.exposeinvocationinterceptor.invoke(exposeinvocationinterceptor.java:92) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:179) @ org.springframework.aop.framework.jdkdynamicaopproxy.invoke(jdkdynamicaopproxy.java:213) @ com.sun.proxy.$proxy75.findbyfirstnameorlastname(unknown source) @ example.springdata.jpa.simple.simpleuserrepositorytests.findbyfirstnameorlastname(simpleuserrepositorytests.java:86) ==================================================================================================================== @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:483) @ org.junit.runners.model.frameworkmethod$1.runreflectivecall(frameworkmethod.java:50) @ org.junit.internal.runners.model.reflectivecallable.run(reflectivecallable.java:12) @ org.junit.runners.model.frameworkmethod.invokeexplosively(frameworkmethod.java:47) @ org.junit.internal.runners.statements.invokemethod.evaluate(invokemethod.java:17) @ org.junit.internal.runners.statements.runbefores.evaluate(runbefores.java:26) @ org.springframework.test.context.junit4.statements.runbeforetestmethodcallbacks.evaluate(runbeforetestmethodcallbacks.java:75) @ org.springframework.test.context.junit4.statements.runaftertestmethodcallbacks.evaluate(runaftertestmethodcallbacks.java:86) @ org.springframework.test.context.junit4.statements.springrepeat.evaluate(springrepeat.java:84) @ org.junit.runners.parentrunner.runleaf(parentrunner.java:325) @ org.springframework.test.context.junit4.springjunit4classrunner.runchild(springjunit4classrunner.java:252) @ org.springframework.test.context.junit4.springjunit4classrunner.runchild(springjunit4classrunner.java:94) @ org.junit.runners.parentrunner$3.run(parentrunner.java:290) @ org.junit.runners.parentrunner$1.schedule(parentrunner.java:71) @ org.junit.runners.parentrunner.runchildren(parentrunner.java:288) @ org.junit.runners.parentrunner.access$000(parentrunner.java:58) @ org.junit.runners.parentrunner$2.evaluate(parentrunner.java:268) @ org.springframework.test.context.junit4.statements.runbeforetestclasscallbacks.evaluate(runbeforetestclasscallbacks.java:61) @ org.springframework.test.context.junit4.statements.runaftertestclasscallbacks.evaluate(runaftertestclasscallbacks.java:70) @ org.junit.runners.parentrunner.run(parentrunner.java:363) @ org.springframework.test.context.junit4.springjunit4classrunner.run(springjunit4classrunner.java:191) @ org.junit.runner.junitcore.run(junitcore.java:137) @ com.intellij.junit4.junit4ideatestrunner.startrunnerwithargs(junit4ideatestrunner.java:117) @ com.intellij.junit4.junit4ideatestrunner.startrunnerwithargs(junit4ideatestrunner.java:42) @ com.intellij.rt.execution.junit.junitstarter.preparestreamsandstart(junitstarter.java:262) @ com.intellij.rt.execution.junit.junitstarter.main(junitstarter.java:84) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:483) @ com.intellij.rt.execution.application.appmain.main(appmain.java:147)
by default, interfaces not retain parameter name information — in no java version, not debug
flag set. java 8 added feature enable retention of parameter information types through new -parameters
compiler flag needs set explicitly.
see an example of in spring data examples repository.
Comments
Post a Comment