Spring 弹簧数据neo4j:can';无法按相关实体查找节点实体

Spring 弹簧数据neo4j:can';无法按相关实体查找节点实体,spring,neo4j,spring-data,spring-data-neo4j,Spring,Neo4j,Spring Data,Spring Data Neo4j,使用SpringDataNeo4j,我有两个节点实体:snippet和person。每个片段都有作者。以下是失败的类别和测试: @NodeEntity public class SnippetLink { @GraphId @GeneratedValue Long id; @Fetch @RelatedTo(type = "AUTHORED") @Indexed PersonLink author; @RelatedToVia(

使用SpringDataNeo4j,我有两个节点实体:snippet和person。每个片段都有作者。以下是失败的类别和测试:

@NodeEntity
public class SnippetLink {
    @GraphId
    @GeneratedValue
    Long id;

    @Fetch
    @RelatedTo(type = "AUTHORED")
    @Indexed
    PersonLink author;

    @RelatedToVia(type = SnippetRelation.DERIVED_FROM)
    SnippetLink parent;

    Long documentId;

    public SnippetLink() {
    }

    public SnippetLink(PersonLink author, Long documentId) {
        this.author = author;
        this.documentId = documentId;
    }

    public PersonLink getAuthor() {
        return author;
    }

    public void setAuthor(PersonLink author) {
        this.author = author;
    }

    public Long getDocumentId() {
        return documentId;
    }

    public void setDocumentId(Long documentId) {
        this.documentId = documentId;
    }

    public SnippetLink getParent() {
        return parent;
    }

    public void setParent(SnippetLink parent) {
        this.parent = parent;
    }

    public SnippetRelation fork(PersonLink author) {
        SnippetLink child = new SnippetLink(author, documentId);
        return new SnippetRelation(this, child, SnippetRelation.Type.Fork);
    }

    public SnippetRelation revision(Long documentId) {
        SnippetLink child = new SnippetLink(getAuthor(), documentId);
        return new SnippetRelation(this, child, SnippetRelation.Type.Revision);
    }
}

公共接口SnippetLinkRepository扩展了GraphRespository{
Iterable findByAuthor(PersonLink作者);
}

PersonLink author=template.save(新PersonLink(“johns”、“John”、“Smith”);
SnippetLink snippet=template.save(新的SnippetLink(author,-1L));
SnippetRelation revisionRelation=snippet.revision(-2L);
保存(revisionRelation.getChild());
模板保存(修改关系);
Iterable snippets=snippetLinkRepository.findbyauther(作者);
assertThat(片段).hasSize(2);
这应该是

当您想要访问实体的关系(实体)时,使用RelatedToVia。
但是,由于SnippetLink是一个实体,因此需要使用realatedTo。

缺少
SnippetRelation
类代码。
@NodeEntity
public class PersonLink {
    @GraphId
    Long id;

    String login;

    String firstName;

    String lastName;

    public PersonLink() {
    }

    public PersonLink(String login, String firstName, String lastName) {
        this.login = login;
        this.firstName = firstName;
        this.lastName = lastName;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
}
public interface SnippetLinkRepository extends GraphRepository<SnippetLink>{
    Iterable<SnippetLink> findByAuthor(PersonLink author);
}
PersonLink author = template.save(new PersonLink("johns", "John", "Smith"));

SnippetLink snippet = template.save(new SnippetLink(author, -1L));

SnippetRelation revisionRelation = snippet.revision(-2L);
template.save(revisionRelation.getChild());
template.save(revisionRelation);

Iterable<SnippetLink> snippets = snippetLinkRepository.findByAuthor(author);
assertThat(snippets).hasSize(2);
@RelatedToVia(type = SnippetRelation.DERIVED_FROM)
SnippetLink parent;
@RelatedTo(type = SnippetRelation.DERIVED_FROM)
SnippetLink parent;