How to specify a JPA named parameter surrounded by wildcards?

前端 未结 3 536
眼角桃花
眼角桃花 2020-12-09 07:44

How would I specify a JPA query like:

Query q = 
  em.createQuery(
    \"SELECT x FROM org.SomeTable x WHERE x.someString LIKE \'%:someSymbol%\'\"
  );


        
相关标签:
3条回答
  • 2020-12-09 07:56

    For reference, you could also use CONCAT:

    like CONCAT('%', :someSymbol, '%')
    
    0 讨论(0)
  • 2020-12-09 08:00

    How about

    Query q = 
      em.createQuery(
        "SELECT x FROM org.SomeTable x WHERE x.someString LIKE :someSymbol"
    );
    q.setParameter("someSymbol", "%someSubstring%");
    

    I'm pretty sure I once solved your problem like that.

    0 讨论(0)
  • 2020-12-09 08:06

    query.setParameter(someSymbol, "%" + someSymbol+ "%");

    0 讨论(0)
提交回复
热议问题