我尝试在RelathionEntity上保存属性
正如我在这里读到的那样
How to CRUD @RelationshipEntity in SDN 4.0
这可以保存一个起始/结束节点,但我注意到这是极端缓慢而不是用deth 0保存节点(保存深度为0的节点大约需要2ms,保存深度为1的节点需要1000毫秒)。我尝试保存的节点只有4个关系
我还在注释为@RelationshipEntity的对象上尝试了session.save(...)(org.neo4j.ogm.session.Session),但它没有做任何事情
我使用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");
添加节点花费不到100毫秒,第一次更新(setPropertyAB(&#34; newProperty1&#34;)之后的保存)大约需要1秒,下一次更新大约需要4秒,最后一次更新大约需要7秒
答案 0 :(得分:1)
根据Michael Hunger的建议,这些性能问题已在版本中修复:
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm</artifactId>
<version>1.1.3-SNAPSHOT</version>
</dependency>
在1.1.3发布之前,您需要向快照存储库添加依赖项:
<repository>
<id>neo4j-snapshots</id>
<url>http://m2.neo4j.org/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
我们使用我们的解决方案进行了测试。