簡體   English   中英

像條件在JPA @Query中不起作用

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM