[英]Spring Data JPA Query with LIKE condition throws exception on runtime
[英]Like condition is not working in JPA @Query
我使用的條件是JPA,我正面臨這個問題。
@Query("select new com.tivo.extract.config.model.DTO(s.SourceId, s.SourceName, t.TvsourceLongName) from MyTelevisionSource t join fetch RCMSource s ON s.SourceId = t.SourceId where s.SourceId LIKE ?1% ")
List<DTO> findFilteredSourceList(String seachInput);
如果我正在使用s.SourceId
像%?1% --> %searchInput% ->
其工作
但是對於s.SourceId
LIKE ?1% -> searchInput% ->
它不起作用
數據庫中Long類型的SourceId
列。
我有一個例外 :
Parameter value [021%] did not match expected type [java.lang.Long (n/a)];
nested exception is java.lang.IllegalArgumentException:
Parameter value [021%] did not match expected type [java.lang.Long (n/a)]
嘗試玩CONCAT
:
@Query("select new com.tivo.extract.config.model.DTO(s.SourceId, s.SourceName, t.TvsourceLongName)
from MyTelevisionSource t join fetch RCMSource s ON s.SourceId = t.SourceId
where s.SourceId LIKE CONCAT(?1,'%') ")
List<DTO> findFilteredSourceList(String seachInput);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.