我尝试在 RelathionEntity 上保存属性
正如我在这里读到的
如何在 SDN 4.0 中对 @RelationshipEntity 进行 CRUD
这可以保存一个开始/结束节点,但我注意到这非常慢,而不是保存一个深度为 0 的节点(保存深度为 0 的节点大约需要 2 毫秒,保存深度为 1 的节点大约需要 1000 毫秒)。我要保存的节点只有 4 个关系
我也尝试过 session.save(...) (org.neo4j.ogm.session.Session) 在注释为 @RelationshipEntity 的对象上,但它什么也没做
我使用 spring-data-neo4j 4.0.0.RELEASE 和 Neo4j 2.2.5
遵循实体和关系的代码:
@NodeEntity
public class EntityA{
@GraphId
private Long nodeId;
private String propertyA;
@Relationship(type = "RelationshipAB", direction = Relationship.OUTGOING)
private Set<RelationshipAB> entitiesB = new HashSet<RelationshipAB>();
}
@NodeEntity
public class EntityB{
@GraphId
private Long nodeId;
private String propertyB;
}
@RelationshipEntity(type = "RelationshipAB")
public class RelationshipAB{
@GraphId
private Long nodeId;
@StartNode
private EntityA entityA;
@EndNode
private EntityB entityB;
@Property
private String propertyAB;
}
遵循一个简单的测试用例来检查性能:
EntityA entityA = new EntityA();
entityA.setPropertyA("propertyA");
entityARepository.save(entityA);
for (int i = 0; i < 100; i++) {
EntityB entityB = new EntityB();
entityB.setPropertyB("propertyB-" + i);
entityBRepository.save(entityB);
RelationshipAB rel = new RelationshipAB();
rel.setEntityA(entityA);
rel.setEntityB(entityB);
rel.setPropertyAB("propertyAB-" + i);
entityA.getEntitiesB().add(rel);
Date startDate = new Date();
entityARepository.save(entityA, 1);
Date endDate = new Date();
System.out.println("Time for adding " + (i + 1) + " node: " + (endDate.getTime() - startDate.getTime()) + " ms");
}
Iterator<RelationshipAB> iter = entityA.getEntitiesB().iterator();
for (int i = 0; i < 10; i++) {
iter.next();
}
iter.next().setPropertyAB("newProperty1");
Date startDate = new Date();
entityARepository.save(entityA, 1);
Date endData = new Date();
System.out.println("Time for cahnge the first relationship property: " + (endData.getTime() - startDate.getTime()) + " ms");
for (int i = 0; i < 20; i++) {
iter.next();
}
iter.next().setPropertyAB("newProperty2");
startDate = new Date();
entityARepository.save(entityA, 1);
endData = new Date();
System.out.println("Time for cahnge the second relationship property: " + (endData.getTime() - startDate.getTime()) + " ms");
for (int i = 0; i < 10; i++) {
iter.next();
}
iter.next().setPropertyAB("newProperty3");
startDate = new Date();
entityARepository.save(entityA, 1);
endData = new Date();
System.out.println("Time for cahnge the third relationship property: " + (endData.getTime() - startDate.getTime()) + " ms");
添加节点不到100ms,第一次更新(setPropertyAB("newProperty1")之后的保存)约1s,下一次更新约4s,最后一次约7s