0
在我的項目中,我有MapNodes,它們通過關係ConnectRelation
連接。 ConenctRelation
有一個屬性長度。節點及其關係保存到Neo4J
數據庫中沒有問題。但是當加載節點時,relationsList
是空的。Neo4j-OGM關係未加載
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
在感謝較大提前!
你是對的類型定義缺失。添加它修復了它。 在重新創建項目時,我一定會下滑。 再次感謝! –