【问题标题】:Unable to cast ltree JPARepository无法投射 ltree JPARepository
【发布时间】:2020-10-12 23:16:36
【问题描述】:

本机查询:

1. SELECT * from test where path <@ 'a.b.c' and path <> 'a.b.c';
2. SELECT * FROM test WHERE path ~ '*.b.c.*{1}'

JPA:

@Query(value = "select * from test where path <@ 'a.b.c' and path <> 'a.b.c'", nativeQuery = true)
List<Test> getAllPath(@Param("pathToSearch") String pathToSearch);

我想用 pathToSearch 参数替换 a.b.c

错误:

Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: ltree <@ character varying
  Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.

【问题讨论】:

    标签: postgresql spring-boot hibernate jpa spring-data-jpa


    【解决方案1】:

    有效

    @Query(value = "SELECT * FROM test WHERE path <@ CAST(:pathToSearch AS ltree) and path <> CAST(:pathToSearch AS ltree)", nativeQuery = true)
    

    【讨论】:

      猜你喜欢
      • 2017-03-17
      • 2012-04-29
      • 2014-06-04
      • 2012-08-23
      • 2013-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多