虽然使用Spring引导对Spring Neo4j编写了poc,但我发现它看起来是Bolt驱动程序和Http驱动程序之间的不一致行为。基本上,在保存2个节点之间的丰富关系之后,使用Bolt驱动程序时,测试无法加载它,但使用Http驱动程序尝试时完全相同的测试会成功。Spring Neo4j - 当Http驱动程序成功执行时,螺栓驱动程序无法加载关系
示例项目可以从github
下载这是一个非常基本的/直接的测试,唯一的先决条件是,你将需要有Neo4j的3启用了螺栓接头安装。
正如安德烈建议请找代码的有关章节如下:
@NodeEntity(label = "Person")
public class Person {
private Long id;
private String firstname;
private String lastname;
@Relationship(type = "HAS_CONTACT", direction = Relationship.INCOMING)
private Contact contact;
// getters and setters here .........
}
@NodeEntity(label = "BankAccount")
public class BankAccount {
private Long id;
private Integer balance;
@Relationship(type = "HAS_CONTACT")
private List<Contact> contacts = new ArrayList<>();
// getters and setters here .........
}
@RelationshipEntity(type = "HAS_CONTACT")
public class Contact {
public Contact() {
}
public Contact(BankAccount bankAccount, Person person) {
this.bankAccount = bankAccount;
this.person = person;
this.bankAccount.getContacts().add(this);
this.person.setContact(this);
}
private Long id;
@StartNode
private BankAccount bankAccount;
@EndNode
private Person person;
private String email;
private String phoneNumber;
// getters and setters here .........
}
@Repository
public interface ContactRepository extends GraphRepository<Contact> {
@Query("MATCH (a:BankAccount)-[r:HAS_CONTACT]->(:Person) " +
"WHERE ID(a)={accountId} " +
"RETURN r")
Iterable<Contact> findByAccountId(@Param("accountId") Long accountId);
}
节省1个帐户后,1人以及它们之间1种的接触关系,下面的查询是失败的一个:
Iterable<Contact> contacts = contactRepository.findByAccountId(accountId);
// this assertion will Fail for the BOLT driver, however, it will Succeed for the HTTP driver
// if the accountRepository.findOne(accountId) statement is executed before calling
// contactRepository.findByAccountId(accountId) then the test will also succeed for the BOLT driver
assertThat(size(contacts), is(1));
你应该在你的问题中包含相关部分的代码。最终,外部链接不可用,并阻止潜在用户从您的帖子中受益。 – Andrej
新增,感谢您的建议 – artemisian