gpt4 book ai didi

java - Neo4j-OGM 关系未加载

转载 作者:行者123 更新时间:2023-12-02 04:05:17 24 4
gpt4 key购买 nike

在我的项目中,我有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 中的关系字段为空,即使深度设置为大于 1 时也是如此。

提前致谢!

最佳答案

我能看到的唯一明显的事情是 @RelationshipEntity 上没有定义关系类型。 -

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

可能是这样 - 请添加它,如果关系仍未加载,您可以打开调试并分享任何感兴趣的内容吗?添加

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

到logback.xml

关于java - Neo4j-OGM 关系未加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34353807/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com