Я использую 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;
}
Может кто-нибудь помочь мне объяснить, почему и как это исправить.Спасибо ...