spring data neo4j @Query by relationship type

spring data neo4j @Query by relationship type

我需要按关系类型查询neo4j

这是我的实体class

@NodeEntity
@Getter
@Setter
@NoArgsConstructor
public class ProductRecommendation {
    @GraphId
    private Long id;

    String product;
    @Relationship(type = "RECOMMENDS", direction = Relationship.OUTGOING)
    Set<ProductRecommendation> linkedProducts = new HashSet<>();
}

我需要找到关系类型为 "RECOMMENDS" 的所有节点。
是否有默认的 findBy 方法?
我试过这个并且有效

public interface ProductRecommendationRepository extends GraphRepository<ProductRecommendation> {
    @Query("MATCH p=()-[r:RECOMMENDS]->() RETURN p")
    List<ProductRecommendation> findByRelationShipType();
}

但是,如果我将关系类型作为变量传递,它就不起作用

public interface ProductRecommendationRepository extends GraphRepository<ProductRecommendation> {
    @Query("MATCH p=()-[r:{0}]->() RETURN p")
    List<ProductRecommendation> findByRelationShipType(String type);
}

谁能解释一下。

谢谢

关系类型无法参数化(参见http://neo4j.com/docs/developer-manual/current/cypher/#cypher-parameters)。

所以你必须选择

public interface ProductRecommendationRepository extends GraphRepository<ProductRecommendation> { @Query("MATCH p=()-[r:RECOMMENDS]->() RETURN p") List<ProductRecommendation> findByRelationShipType(); }