Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/154.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JPA Postgres查询树路径_Java_Hibernate_Postgresql_Jpa_Ltree - Fatal编程技术网

Java JPA Postgres查询树路径

Java JPA Postgres查询树路径,java,hibernate,postgresql,jpa,ltree,Java,Hibernate,Postgresql,Jpa,Ltree,使用弹簧靴和postgres。数据库中有分层数据,路径存储在ltree列中。我试图根据路径获取特定对象,但在查询数据库时遇到问题 模型类: @Entity @Table(schema = "devschema", name = "family") public class Family { @Id @Column(name = "member_id") private Long memId; @Column(name = "name") privat

使用弹簧靴和postgres。数据库中有分层数据,路径存储在ltree列中。我试图根据路径获取特定对象,但在查询数据库时遇到问题

模型类:

@Entity
@Table(schema = "devschema", name = "family")

public class Family {

    @Id
    @Column(name = "member_id")
    private Long memId;

    @Column(name = "name")
    private String memName;

    @Column(name = "fam_path",  columnDefinition="ltree")
    private String familyPath;

    ... getters and setters
}
存储库类:

  public interface OrgRepository extends PagingAndSortingRepository <Family, Long>{

    public Family findByMemId(Long id);
    public Family findByMemName(String memName);

    @Query("select f from Family f where familyPath = ?1")
    public Family findByPath(String path);
    }

我试图将f转换为文本,但没有效果。有人知道如何解决问题吗?

您选择了错误的操作员

可用的操作符,如@>PostgreSQL文档,表示这些操作符需要gist索引。我发现在一个大数据集上速度要慢得多。(我把它拿走了。)

所以我一直在使用tilde操作符,这让我很满意。它不需要gist索引

select * from Family where familyPath ~ '*.Smith.*'
或者,如果您知道它始终是路径的终点,请留下我们的最后一个星号:

select * from Family where familyPath ~ '*.Smith'

请参见,为了更好地理解,您应该在答案中包含代码的必要部分
select * from Family where familyPath ~ '*.Smith'