雖然使用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