JPA Like Operator with Integer

前端 未结 4 1584
南旧
南旧 2020-12-11 06:52

Can someone tell me, why this is not working:

criteria.add(cb.like((myentity.get(\"integerid\")).as(String.class), \"2%\"))

4条回答
  •  独厮守ぢ
    2020-12-11 07:38

    Here are example of how it work with JPA, so u can use LIKE with integer inside your JPQL.

    public List getMyEntities(String idStr) {
       return entityManager.createQuery("SELECT m FROM MyEntity m WHERE CAST( m.id AS string ) LIKE :idStr")
             .setParameter("idStr", "%" + idStr+ "%").getResultList();
    }
    

    Note: i tested it and worked fine with me, i am using JPA 2.1 with Hibernate provider.

提交回复
热议问题