Neo4j自定义密码(@Query)不能按预期工作

时间:2018-12-03 08:53:03

标签: java neo4j

我正在将Neo4j 3.5.0与SprintBoot 2.1.0.RELEASE一起使用

implementation('org.springframework.boot:spring-boot-starter-data-neo4j')

我对自定义Cypher有疑问。

@Query("MATCH (p:Product {productId:{productId}})-[r:RELATED]-(:Product) RETURN r")
List<Related> findRelative(@Param("productId") String id);

当我在服务中调用该方法时,我总是收到空结果,而不是neo4j服务器拥有数据。 如果我在getAll方法之前添加findRelative方法,则结果现在可以。

    // relatedRepository.findAll(); The method will return correct data if I un-comment that line.
    Collection<Related> relateds = relatedRepository.findRelative(id);
    System.out.println(relateds.size());

在我的项目中听到一些配置:

--- application.yml ---

spring.data.neo4j.uri: bolt://localhost:7687

--- Application.java ---

@SpringBootApplication
@EnableNeo4jRepositories()
@EnableTransactionManagement
public class LeafeonApplication {

    public static void main(String[] args) {
        SpringApplication.run(LeafeonApplication.class, args);
    }
}

--- Related.java ---

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@RelationshipEntity(type = "RELATED")
public class Related {

    @Id
    @GeneratedValue
    private Long id;

    private Integer weight;

    @StartNode
    private Product start;

    @EndNode
    private Product end;

    public void increaseWeight() {
        if (weight == null) {
            weight = 0;
        }
        weight++;
    }
}

--- Product.java ---

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@NodeEntity
public class Product {

    @Id
    private String productId;

    private String name;

    @Relationship(type = "RELATED", direction = Relationship.UNDIRECTED)
    private Set<Related> related;
}

谁能帮我解释为什么以及如何解决。 谢谢...

0 个答案:

没有答案