Reputation: 21
I try to save properties on a RelathionEntity
As i read here
How to CRUD @RelationshipEntity in SDN 4.0
this is possible saving one of the start/end node, but i notice that this is extreme slow instead of saving a node with deth 0 (saving a node with depth 0 takes about 2ms, saving a node with depth 1 takes about 1000ms). The node that I'm trying to save has only 4 relationships
I've tried also session.save(...) (org.neo4j.ogm.session.Session) on an object annotated as @RelationshipEntity, but it does nothing
I use spring-data-neo4j 4.0.0.RELEASE and Neo4j 2.2.5
Follow the code for entities and relationships:
@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;
}
Follow a simple test case for checking the performace:
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");
The adding nodes takes less than 100ms, the first update (the save after setPropertyAB("newProperty1")) takes about 1s, the next update takes about 4s and the last one about 7s
Upvotes: 1
Views: 195
Reputation: 21
As suggested from Michael Hunger, this performance problems are fixed in version:
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm</artifactId>
<version>1.1.3-SNAPSHOT</version>
</dependency>
Until 1.1.3 is released, you'll need to add a dependency to the snapshots repository:
<repository>
<id>neo4j-snapshots</id>
<url>http://m2.neo4j.org/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
We tested it with our solution.
Upvotes: 1