未加载 Neo4j-OGM 关系
Neo4j-OGM relations not being loaded
在我的项目中,我有 MapNodes,它们通过关系 ConnectRelation
连接。 ConenctRelation
的长度为 属性。节点及其关系毫无问题地保存到 Neo4J
数据库中。但是在加载节点时,relationsList
是空的。
地图节点class
@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;
}
.
.
连接关系class:
@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 也是如此。
提前致谢!
我能看到的唯一明显的事情是 @RelationshipEntity
-
上没有定义关系类型
@RelationshipEntity(type = "CONNECTS_TO")
public class ConnectRelation...
可能是这样 - 请添加它,如果关系仍未加载,您可以打开调试并分享任何感兴趣的内容吗?
添加
<logger name="org.neo4j.ogm" level="debug" />
到logback.xml
在我的项目中,我有 MapNodes,它们通过关系 ConnectRelation
连接。 ConenctRelation
的长度为 属性。节点及其关系毫无问题地保存到 Neo4J
数据库中。但是在加载节点时,relationsList
是空的。
地图节点class
@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;
}
.
.
连接关系class:
@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 也是如此。
提前致谢!
我能看到的唯一明显的事情是 @RelationshipEntity
-
@RelationshipEntity(type = "CONNECTS_TO")
public class ConnectRelation...
可能是这样 - 请添加它,如果关系仍未加载,您可以打开调试并分享任何感兴趣的内容吗? 添加
<logger name="org.neo4j.ogm" level="debug" />
到logback.xml