Reputation: 55
In my project I have MapNodes, which are connected by a relation ConnectRelation
. ConenctRelation
has a property length. Nodes and their relations are saved to the Neo4J
database without problems. But when loading the Nodes, the relationsList
is empty.
MapNode 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;
}
.
.
ConnectRelation 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;
.
.
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.
Thanks in Advance!
Upvotes: 0
Views: 358
Reputation: 19373
The only obvious thing I can see is the relationship type not being defined on the @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
Upvotes: 2