Neo4j OGM RelationsEntity 缺少开始或结束节点



当我尝试在两个节点实体(BundleImpl和PackageFragmentImpl(之间设置导出关系时,我收到错误消息,指出缺少开始或结束节点。我感谢任何帮助。谢谢!

@NodeEntity
public class BundleImpl{
protected List<PackageFragmentImpl> exports;
@Relationship(type = "EXPORT", direction = "OUTGOING")
private Export exportRelation = new Export();
public Export getExport(){
    return exportRelation;
}
public void setExport(Export exportRelation){
    this.exportRelation = exportRelation;
}

@NodeEntity
public class PackageFragmentImpl {
protected BundleImpl bundle;
@Relationship(type = "EXPORT")
private Export exportRelation = new Export();
public Export getExport(){
    return exportRelation;
}
public void setExport(Export exportRelation){
    this.exportRelation = exportRelation;
}

@RelationshipEntity(type="EXPORT")
public class Export {
@GraphId 
Long id;
@StartNode
BundleImpl startBundle;
@EndNode
PackageFragmentImpl endPackageFrag;

public long timestamp;
public Export(){
}
public Export(BundleImpl startBundle, PackageFragmentImpl endPackageFrag, 
long timestamp){
    this.startBundle = startBundle;
    this.endPackageFrag = endPackageFrag;
    this.timestamp = timestamp;
}
// Getter & Setter

在我的主要方法的以下部分中,我设置了两个节点之间的关系并检查它们是否确实存在:

Export exportRelation = new Export(bundle, fragment, date);
bundle.setExport(exportRelation);
fragment.setExport(exportRelation);

运行程序后我得到的详细错误信息是:

Exception in thread "main" org.neo4j.ogm.exception.MappingException: 
Relationship entity OSGiApplicationModel.impl.Export@1c491240 cannot have 
a missing start or end node
at org.neo4j.ogm.context.EntityGraphMapper.haveRelationEndsChanged(EntityGraphMapper.java:520)
at org.neo4j.ogm.context.EntityGraphMapper.getRelationshipBuilder(EntityGraphMapper.java:484)
at org.neo4j.ogm.context.EntityGraphMapper.link(EntityGraphMapper.java:447)
at org.neo4j.ogm.context.EntityGraphMapper.mapEntityReferences(EntityGraphMapper.java:390)
at org.neo4j.ogm.context.EntityGraphMapper.mapEntity(EntityGraphMapper.java:222)
at org.neo4j.ogm.context.EntityGraphMapper.mapRelatedEntity(EntityGraphMapper.java:717)
at org.neo4j.ogm.context.EntityGraphMapper.link(EntityGraphMapper.java:457)
at org.neo4j.ogm.context.EntityGraphMapper.mapEntityReferences(EntityGraphMapper.java:378)
at org.neo4j.ogm.context.EntityGraphMapper.mapEntity(EntityGraphMapper.java:222)
at org.neo4j.ogm.context.EntityGraphMapper.mapRelatedEntity(EntityGraphMapper.java:717)
at org.neo4j.ogm.context.EntityGraphMapper.link(EntityGraphMapper.java:457)
at org.neo4j.ogm.context.EntityGraphMapper.mapEntityReferences(EntityGraphMapper.java:390)
at org.neo4j.ogm.context.EntityGraphMapper.mapEntity(EntityGraphMapper.java:222)
at org.neo4j.ogm.context.EntityGraphMapper.mapRelatedEntity(EntityGraphMapper.java:717)
at org.neo4j.ogm.context.EntityGraphMapper.link(EntityGraphMapper.java:457)
at org.neo4j.ogm.context.EntityGraphMapper.mapEntityReferences(EntityGraphMapper.java:378)
at org.neo4j.ogm.context.EntityGraphMapper.mapEntity(EntityGraphMapper.java:222)
at org.neo4j.ogm.context.EntityGraphMapper.mapRelatedEntity(EntityGraphMapper.java:717)
at org.neo4j.ogm.context.EntityGraphMapper.link(EntityGraphMapper.java:457)
at org.neo4j.ogm.context.EntityGraphMapper.mapEntityReferences(EntityGraphMapper.java:390)
at org.neo4j.ogm.context.EntityGraphMapper.mapEntity(EntityGraphMapper.java:222)
at org.neo4j.ogm.context.EntityGraphMapper.mapRelatedEntity(EntityGraphMapper.java:717)
at org.neo4j.ogm.context.EntityGraphMapper.link(EntityGraphMapper.java:457)
at org.neo4j.ogm.context.EntityGraphMapper.mapEntityReferences(EntityGraphMapper.java:378)
at org.neo4j.ogm.context.EntityGraphMapper.mapEntity(EntityGraphMapper.java:222)
at org.neo4j.ogm.context.EntityGraphMapper.map(EntityGraphMapper.java:135)
at org.neo4j.ogm.session.delegates.SaveDelegate.save(SaveDelegate.java:83)
at org.neo4j.ogm.session.Neo4jSession.save(Neo4jSession.java:452)
at analysis.ModelStorage.saveModel(ModelStorage.java:42)
at analysis.Main.main(Main.java:100)

我确实认为你的关系方向映射是根本原因:

BundleImpl中,你把你们的关系定义为OUTGOINGPackageFragmentImpl你通过完全跳过方向来做同样的事情。这将默认为 OUTGOING

从文档中:

如果您不关心方向,则可以指定direction=Relations.UNDIRECT,这将保证两个节点实体之间的路径可以从任何一侧导航。

此外,如果要保留没有关系的条目,则Export对象的两个类(private Export exportRelation = new Export();(中的初始设置可能会导致问题,因为OGM实际上会找到没有任何开始或结束节点的RelationshipEntity

最新更新