JPA Like Operator with Integer

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

    I have faced the same issue. I use JPA2.0 and EclipseLink 2.3 as implementation.

    The column codeClient is actually an Integer in my DataBase.

    The annotation @Convert simply convert my Integer column to a String column.

    In that way i can use a like predicate over numbers.

    @Entity
    @Table(name="COLIS_SO_VM")
    public class Colis implements Serializable {
    
        ...
    
        @Convert
        private String codeClient;
    
        ...
    }
    

    I know this is an old post but if it can help someone else !

提交回复
热议问题