在我的项目中,我使用了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中的relations字段是空的,即使深度设置为大于1。
提前谢谢!
发布于 2015-12-18 10:58:31
我能看到的唯一明显的事情是没有在@RelationshipEntity上定义关系类型-
@RelationshipEntity(type = "CONNECTS_TO")
public class ConnectRelation...这是可能的-请添加它,如果关系仍然没有加载,您能打开调试并分享任何感兴趣的东西吗?添加
<logger name="org.neo4j.ogm" level="debug" />
转到logback.xml
https://stackoverflow.com/questions/34353807
复制相似问题