我正在尝试在春季使用MSSQL DB运行自定义查询:
@Query(value = "SELECT my_id, date, name " +
"FROM my_events " +
"WHERE name == :name " +
"AND date between :starttime and :endtime " +
"ORDER BY date DESC",
nativeQuery = true)
List<myDAO> findByNameAndDateBetweenOrderByDateDesc (
@Param("name")String name,
@Param("starttime")String starttime,
@Param("endtime")String endtime
);
在没有自定义查询的情况下运行应用程序时,我会得到:
Name for parameter binding must not be null or empty! On JDKs < 8, you need to use @Param for named parameters, on JDK 8 or better, be sure to compile with -parameters.; nested exception is java.lang.IllegalArgumentException: Name for parameter binding must not be null or empty! On JDKs < 8, you need to use @Param for named parameters, on JDK 8 or better, be sure to compile with -parameters.
在运行不带@Query注释的应用程序时(使用CrudRepository),它可以正常工作。
一旦我确定了上面的简化查询,该查询将变为一个更复杂的查询,这就是为什么我不能使用CrudRepository函数的原因。
答案 0 :(得分:0)
检查这张票:https://jira.spring.io/browse/DATAJPA-1086。 通过添加Maven插件解决了相同的错误:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgument>-parameters</compilerArgument>
</configuration>
</plugin>
</plugins>
</build>