在我的项目中,我有 MapNodes ,它们通过关系ConnectRelation
连接。 ConenctRelation
有一个属性长度。节点及其关系会毫无问题地保存到Neo4J
数据库中。但是在加载节点时,relationsList
为空。
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类:
@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;
.
.
填写并加载方法:
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);
}
});
});
}
我遇到的问题是,加载节点时MapNode中的关系字段为空,即使深度设置为大于1的值。
提前致谢!
答案 0 :(得分:2)
我能看到的唯一显而易见的事情是@RelationshipEntity
-
@RelationshipEntity(type = "CONNECTS_TO")
public class ConnectRelation...
可能就是这样 - 请添加它,如果关系仍未加载,你可以打开调试并分享任何感兴趣的内容吗? 添加
<logger name="org.neo4j.ogm" level="debug" />
到logback.xml