当我尝试在两个NodeEntities(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
在我的main方法的以下部分中,我设置了两个节点之间的关系,并检查它们是否确实存在:
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)
答案 0 :(得分:0)
我认为您的关系方向映射是根本原因:
在BundleImpl
中,您将自己的关系定义为OUTGOING
,而在PackageFragmentImpl
中,您可以通过跳过方向来完成相同的操作。这将默认为OUTGOING
。
来自docs:
如果你不关心方向,那么你可以指定direction = Relationship.UNDIRECTED,这将保证两个节点实体之间的路径可以从任何一方导航。
如果你想要保持没有关系的条目,那么private Export exportRelation = new Export();
对象的两个类(Export
)中的初始设置可能会导致问题,因为OGM会真的找到没有任何开始或结束节点的RelationshipEntity
。