Using Hibernate query : colon gets treated as parameter / escaping colon

前端 未结 6 1312
陌清茗
陌清茗 2020-12-05 18:00
return sessionFactory.getCurrentSession().
            createQuery(\"FROM Weather WHERE city_id = :id AND date \" +
                    \"BETWEEN now()::date AND now         


        
6条回答
  •  我在风中等你
    2020-12-05 18:43

    I just had this problem, had to use casts, so I tried some stuff to make it work. Turns out you escape : in hibernate with \

    However, in java, to print \ to begin with, you have to escape it with \.
    So, if you want to put a : in your SQL hibernate query, you have to write it like: \\:

    And if you wanted to cast in PostgreSQL, such as in my case, you would have to, for example: field\\:\\:int if you wanted to cast some field as an integer.

提交回复
热议问题