2015-12-18 72 views
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

在感謝較大提前!

回答

2

唯一明顯的事情,我可以看到的是沒有在@RelationshipEntity定義的關係類型 -

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

這可能是它 - 請加它,如果仍然沒有加載的關係,你可以把調試分享任何有趣的東西? 添加

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

到logback.xml

+0

你是對的類型定義缺失。添加它修復了它。 在重新創建項目時,我一定會下滑。 再次感謝! –