Postgresql 带有本机查询Java实体管理器的Postgres Ltree扩展

Postgresql 带有本机查询Java实体管理器的Postgres Ltree扩展,postgresql,spring-data,ltree,Postgresql,Spring Data,Ltree,我正在尝试使用本机查询从postgres DB获取一棵树,下一个查询使用psql终端工作正常: SELECT col_1 FROM my_tree WHERE parent_id ~ lquery('*.C.*') 但当我使用实体管理器添加相同的查询时: private List<String> fetchTreeByParentId() { Query query = entityManager.createNativeQuery("SELECT co

我正在尝试使用本机查询从postgres DB获取一棵树,下一个查询使用psql终端工作正常:

SELECT col_1 FROM my_tree WHERE parent_id  ~ lquery('*.C.*')
但当我使用实体管理器添加相同的查询时:

private List<String> fetchTreeByParentId() {
        Query query = entityManager.createNativeQuery("SELECT col_1 FROM my_tree WHERE parent_id  ~ lquery('*.C.*')");
        return query.getResultList();
    }
我发现我错过了一些东西。。。也许可以更新postgresql jar


该项目是spring boot 2.4.2,由于@jjanes,我注意到像
lquery
&
ltree
这样的数据类型在我的数据库模式中,所以我不得不将代码更改为:

1.-使用lquery获取节点以使用诸如“.C”之类的模式

@Query(value=“从{h-schema}my_树中选择my_col,其中parent_id操作符({h-schema}~){h-schema}lquery(:parentId)”,nativeQuery=true)
列出treeByParentId(@Param(“parentId”)字符串parentId);
2.-使用ltree获取节点以使用节点标签,例如“C”

@Query(value = "SELECT my_col from {h-schema}my_tree where parent_id OPERATOR({h-schema}<@) ( "
            + "    SELECT parent_id FROM {h-schema}my_tree WHERE node_label = :parentId "
            + "  );", nativeQuery = true)
List<String> treeByParentId(@Param("parentId") String parentId);

@Query(value=“SELECT my_col from{h-schema}my_tree where parent_id操作符({h-schema})可能您的两个会话具有不同的搜索路径设置?如果您的模式限定了函数会怎样?已经尝试了类似于
从my_schema.my_tree where parent_id~lquery('*.C.*')的模式
以及使用cast
从my_树中选择col_1,其中parent_id~cast('*.C.*'作为lquery)
…使用cast时,错误是数据类型
lquery
不存在
@Query(value = "SELECT my_col FROM {h-schema}my_tree where parent_id OPERATOR({h-schema}~) {h-schema}lquery(:parentId)", nativeQuery = true)
List<String> treeByParentId(@Param("parentId") String parentId);
@Query(value = "SELECT my_col from {h-schema}my_tree where parent_id OPERATOR({h-schema}<@) ( "
            + "    SELECT parent_id FROM {h-schema}my_tree WHERE node_label = :parentId "
            + "  );", nativeQuery = true)
List<String> treeByParentId(@Param("parentId") String parentId);