Using LIKE % in Hibernate

前端 未结 3 581
情歌与酒
情歌与酒 2021-01-22 00:05

How do I use LIKE % in Hibernate. I want to use a SQL with LIKE % in my hbm.xml file. I have 2 queries which I am consolidating to 1.

相关标签:
3条回答
  • 2021-01-22 00:34

    Maybe the user_id is not a char/varchar? You have to convert the user_id with str() to character data first!

    Example:

    SELECT *
    FROM abc.def_vw a
    WHERE user_id = ?
    AND str(user_id) LIKE '%' || ?
    
    0 讨论(0)
  • 2021-01-22 00:39

    Use LIKE '%?%' and second parameter string to make the query. The field also should be a string type because like is used to compare strings.

    0 讨论(0)
  • 2021-01-22 00:47

    3 things to notice:

    • Is user_id string?
    • like in HQL works fine. for example like '%something%'
    • Your query doesn't make sense "where user_id =? and user_id like '%'" what are you trying to do ? Use only one of the conditions.
    0 讨论(0)
提交回复
热议问题