我在本地系统上运行了以下代码:
@Query(value = "select l from TnncSetlmtSvcGrpStagingEntity l where l.runDate >=:runDate")
List<TnncSetlmtSvcGrpStagingEntity> findAllByRunDateGT(Date runDate);
但是当我在更高的环境中运行相同的代码时,我得到了以下错误:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:51)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)
Caused by:
<CDIMIServiceException>
<Message>Exception in CodeTableTp2Controller </Message>
<AdditionalInfo>null</AdditionalInfo>
<Cause>org.springframework.dao.InvalidDataAccessApiUsageException: For queries with named parameters you need to use provide names for method parameters.
Use @Param for query method parameters, or when on Java 8+ use the javac flag -parameters.; nested exception is java.lang.IllegalStateException:
For queries with named parameters you need to use provide names for method parameters.
Use @Param for query method parameters, or when on Java 8+ use the javac flag -parameters.</Cause> </CDIMIServiceException>
at com.visa.cdimi.code.table.tp2.CodeTableTp2Controller.execute(CodeTableTp2Controller.java:51)
at com.visa.cdimi.code.table.tp2.Application.main(Application.java:31)
... 8 more
Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: For queries with named parameters you need to use provide names for method parameters.
Use @Param for query method parameters, or when on Java 8+ use the javac flag -parameters.;
nested exception is java.lang.IllegalStateException: For queries with named parameters you need to use provide names for method parameters.
Use @Param for query method parameters, or when on Java 8+ use the javac flag -parameters.
at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:371)
我检查了服务器上的java版本,它是:
java version "1.8.0_261"
Java(TM) SE Runtime Environment (build 1.8.0_261-b25)
Java HotSpot(TM) 64-Bit Server VM (build 25.261-b25, mixed mode)
在我的本地系统上,我也使用Java 8。
任何人都可以请帮助我解决这个问题。任何帮助是感激。
2条答案
按热度按时间dgiusagp1#
是否尝试使用命名参数?
6.3.6.使用命名参数默认情况下,Spring Data JPA使用基于位置的参数绑定,如前面所有示例中所述。这使得查询方法在重构参数位置时容易出错。要解决此问题,您可以使用@Param annotation为方法参数提供具体名称并在查询中绑定该名称
详情请访问https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.named-parameters。
所以,这应该行得通:
js4nwp542#
当方法参数名不能被反射读取时会发生此问题,
javac -parameters
标志确保这些参数在运行时可用。如果您遇到此问题,请确保您的类是使用-parameters
编译的,在Eclipse中,您可以通过进入Windows〉Preferences〉Java〉Compiler,然后确保选项“Store information about method parameters”已选中。或者,如果您使用每个项目设置,请转到项目“右键单击”〉属性(快捷方式:Alt+Enter),导航到“Java编译器”并确保选中上述选项