How do I use spring data jpa to query jsonb column?

后端 未结 5 1963
小蘑菇
小蘑菇 2020-12-29 12:11

I\'m having a problem getting this native query right against a postgres 9.4 instance.

My repository has a method:

 @Query(value = \"SELECT t.* \" +
         


        
5条回答
  •  情歌与酒
    2020-12-29 13:02

    You can also use the FUNC JPQL keywork for calling custom functions and not use a native query.
    Something like this,

    @Query(value = "SELECT t FROM my_table t "
            + "WHERE t.field_1=:field_1 AND t.field_2=1 AND t.field_3 IN :field_3 "
            + "AND FUNC('jsonb_extract_path_text', 'key', 'subkey')=:value")
    List getEntities(@Param("field_1") String field_1, @Param("field_3") Collection field_3, @Param("value") String value);
    

提交回复
热议问题