0

I am using like condition is JPA, I am facing the issue.

@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);

If i am using s.SourceId like %?1% --> %searchInput% -> its working

but for s.SourceId LIKE ?1% -> searchInput% -> its not working

SourceId column in Long type in DB.

I am getting an exception:

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)]
Dushyant Tankariya
  • 1,432
  • 3
  • 11
  • 17
mohan
  • 447
  • 4
  • 11
  • 26
  • 2
    Maybe `SourceId` is an number and `seachInput` is some texte ... – Zorglube Jul 26 '19 at 12:23
  • i think it is because source id is Long https://stackoverflow.com/questions/18462376/like-operator-for-integer – Ryuzaki L Jul 26 '19 at 12:24
  • @Zorglube, its working if i am giving s.SourceId like %?1%, can you suggest how to use s.SourceId like ?1%, because i want post search. – mohan Jul 29 '19 at 05:07
  • 1
    @mohan, you can't use `LIKE` on a number. On a number you can do `>` or `=` or `<`. If oyu whant to do some `LIKE` you have to transform your number on a string. – Zorglube Jul 29 '19 at 08:19

1 Answers1

0

Try to play around with 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);
Maciej Kowalski
  • 25,605
  • 12
  • 54
  • 63