JPA Like Operator with Integer

前端 未结 4 1585
南旧
南旧 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:30

    JPA does not support like() with Integers, only Strings. Some databases do support like with integer and others do not.

    EclipseLink should allow usage of like() with Integer (provided your database supports it). What version are you using? May need to use >= 2.1. If it fails on the latest version, then please log a bug.

    You can also convert the integer to a string using a "CHAR, "TO_CHAR" or "CONVERT" function depending on your database. The criteria API supports a function() API to call a native function.

    Note that the as() API is not intended for converting from Integer to String, it is for casting to a subclass entity.

提交回复
热议问题