[英]Using a custom MSSQL query in spring
我正在嘗試在春季使用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函數的原因。
檢查這張票: 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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.