我正在嘗試使用 jpa 撰寫查詢,但我不能。我試過:
@Query(value="select count(id_ass) from assenza where id_dip=?1 and data_ass between ?2 and ?3", nativeQuery = true)
Integer getAssenzeByid_dipmese(int id_dip,String inizio, String fine);
但我明白了 ERROR: operator does not exist: date >= character varying
然后我嘗試使用
@Query(value="select count(id_ass) from assenza where id_dip=?1 and data_ass >= ?2 and data_ass<= ?3", nativeQuery = true)
Integer getAssenzeByid_dipmese(int id_dip,String inizio, String fine);
但我得到了同樣的錯誤
然后我嘗試轉換日期中的字串但它沒有用...有人可以告訴我我做錯了什么嗎?謝謝
uj5u.com熱心網友回復:
由于變數是字串,它們作為 varchars 傳遞。您必須將 varchars 顯式轉換為日期。
@Query(value="select count(id_ass) from assenza where id_dip=?1 and data_ass between CAST(?2 AS DATE) and CAST(?3 AS DATE)", nativeQuery = true)
Integer getAssenzeByid_dipmese(int id_dip,String inizio, String fine);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/345835.html
下一篇:嘗試使用JPA連接到Java中的DockerisedDB2時,物體管理器為空,也使用maven和OpenLiberty
