![](/img/trans.png)
[英]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.