简体   繁体   English

Neo4j-OGM关系未加载

[英]Neo4j-OGM relations not being loaded

In my project I have MapNodes , which are connected by a relation ConnectRelation . 在我的项目中,我有MapNodes ,它们通过关系ConnectRelation连接。 ConenctRelation has a property length. ConenctRelation具有属性长度。 Nodes and their relations are saved to the Neo4J database without problems. 节点及其关系将Neo4J保存到Neo4J数据库中。 But when loading the Nodes, the relationsList is empty. 但是,在加载节点时, relationsList为空。


MapNode class MapNode类

@NodeEntity
public abstract class MapNode extends Circle implements IObservable{

@GraphId
Long id;

@Relationship(type = "CONNECTS_TO")
private ArrayList<ConnectRelation> relations = new ArrayList<>();

@Property(name="x")
private double xCoordinate;

@Property(name="y")
private double yCoordinate;

public ConnectRelation connectToNode(MapNode otherNode){
    ConnectRelation relation = new ConnectRelation(this,otherNode);
    relation.setLength(2);
    this.relations.add(relation);
    return relation;
}
.
.

ConnectRelation class: ConnectRelation类:

@RelationshipEntity
public class ConnectRelation extends Line implements IObserver {

@GraphId
Long id;

@StartNode
MapNode startNode;

@EndNode
MapNode endNode;

@Property(name="startX")
private double startXCoordinate;
@Property(name="startY")
private double startYCoordinate;

@Property(name="endX")
private double endXCoordinate;
@Property(name="endY")
private double endYCoordindate;

@Property(name="length")
private double length;
.
.

Fill and load methods: 填充和加载方法:

 public static void fillDb(){
    getSession().purgeDatabase();

    Room roomOne = new Room();
    roomOne.setXCoordinate(100);
    roomOne.setYCoordinate(100);
    Room roomTwo = new Room();
    roomTwo.setXCoordinate(200);
    roomTwo.setYCoordinate(200);

    ConnectRelation connectRelation = roomOne.connectToNode(roomTwo);

    getSession().save(roomOne);
    getSession().save(roomTwo);
    getSession().save(connectRelation);
}

public void loadNodes(){
    mapNodeList = new ArrayList<>(DatabaseRepository.getSession().loadAll(MapNode.class,2));
    mapNodeList.forEach(n -> {
        n.getRelations().forEach(r -> {
            if(!relationList.contains(r)){
                relationList.add(r);
            }
        });
    });
}

The problem I have is that the relations field in MapNode is empty when loading the nodes, even when the depth is set to something larger than 1. 我遇到的问题是,即使节点的深度设置为大于1,在加载节点时MapNode中的关系字段也为空。

Thanks in Advance! 提前致谢!

The only obvious thing I can see is the relationship type not being defined on the @RelationshipEntity - 我能看到的唯一明显的事情是没有在@RelationshipEntity上定义关系类型-

@RelationshipEntity(type = "CONNECTS_TO")
public class ConnectRelation...

That could be it- please add it and if the relationships are still not loaded, could you turn debug on and share anything of interest? 就是这样-请添加它,如果仍然没有加载关系,您可以打开调试并共享感兴趣的任何东西吗? Add

<logger name="org.neo4j.ogm" level="debug" />

to logback.xml 到logback.xml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM