Neo4j OGM没有保存RelationshipEntity

时间:2018-02-20 10:44:30

标签: java neo4j neo4j-ogm

我已经阅读了关于SO的每一个问题,但我仍然无法弄清楚为什么Neo4j的OGM不能保存我的RelationshipEntities。 这里保存PubmedDocumentNode和PubmedAuthorNode,但不保存关系引用和作者。相反,MeshHeadingsUI边创建得很好。

代码:

@NodeEntity
public class PubmedDocumentNode extends Node {
    @Id
    @Index(unique = true)
    public int PMID;
    ...

    @Relationship(type = "CITES")
    public List<PubmedCitesRelationship> citations;
    @Relationship(type = "MeSHClass")
    public List<MeSHClass> MeshHeadingsUI;
    @Relationship(type = "AUTHOR")
    public List<PubmedDocAuthorRelationship> authors;

    public PubmedDocumentNode() {
        node_type = NODE_TYPE;
        citations = new ArrayList<>();
        MeshHeadingsUI = new ArrayList<>();
        authors = new ArrayList<>();
    }
}

@NodeEntity
public class PubmedAuthorNode extends Node {
    ...

    @Id
    @Index(unique = true)
    public String Author_Name;
    ....
}


@RelationshipEntity(type = "AUTHOR")
public class PubmedDocAuthorRelationship extends FeatureEdge {

    public PubmedDocAuthorRelationship() {
        label = new float[]{3.0f}; //just to try
    }

    @Id
    @GeneratedValue
    public long Id;

    @StartNode
    public PubmedDocumentNode document;
    @EndNode
    public PubmedAuthorNode author;
}

家长班:

public abstract class FeatureEdge extends DistributedNeo4jEntity {
    @Property
    public float label[];

    public FeatureEdge() {
    }
}

public abstract class Node extends DistributedNeo4jEntity {
    ...
    public float state[];
    public float label[];
    ...

    public Node() {
        ...
    }
}

public abstract class DistributedNeo4jEntity extends Neo4jEntity {

    ...
}

public abstract class Neo4jEntity {
    @Labels
    public List<String> labels = new ArrayList<>(); //I already tried to comment this but no luck
}

保存代码:

    //s is obtained by openSession
    Transaction tx = s.beginTransaction();
    arts.forEach(x -> s.save(x));
    //arts.forEach(x -> x.authors.forEach(y -> s.save(y))); //tried also
    //arts.forEach(x -> x.citations.forEach(y -> s.save(y)));  //tried also
    tx.commit();
    tx.close();

0 个答案:

没有答案