Reputation: 588
We are using spring-data-neo4j release 2.2.2.Release and Neo4j 1.9
Saving and updating nodes (properties) works fine using a GraphRepository
Our most simple example looks like this:
public interface LastReadMediaRepository extends GraphRepository<Neo4jLastReadMedia> {}
We also set some relationships connected to a node, the node class looks like this
@NodeEntity
public class Neo4jLastReadMedia {
@GraphId
Long id;
@JsonIgnore
@Fetch @RelatedToVia(type = "read", direction = Direction.OUTGOING)
Set<LastReadMediaToLicense> licenseReferences;
public Neo4jLastReadMedia() {
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public void read(final Neo4jLicense license, final Long lastAccess, final float progress, final Long chapterId) {
licenseReferences.add(new LastReadMediaToLicense(this, license, lastAccess, progress, chapterId));
}
public Set<LastReadMediaToLicense> getLicenseReferences() {
return licenseReferences;
}
@Override
public String toString() {
return "Neo4jLastReadMedia [id=" + id + "]";
}
}
Now, we save a node using the repository's save()
method. The relationships are saved, too, at least for the first save.
Later when we want to change properties on a relationship (update a relationship) that already exists (e.g. lastAccess) we retrieve the node from the database, manipulate its relationship Set, here Set<LastReadMediaToLicense> licenseReferences;
and then, try to save the node back with save()
Unfortunately, the relationship is not updated and all properties remain the same...
We know how to do that using annotated cypher queries in the repo, but there has to be an "abstracted" way?!
Thanks a lot!
Regards
EDIT: If I remove a relationship from the Set, then perform a save() on the node, the relationship is deleted. Only update does not work! Or is that the intention?
Upvotes: 0
Views: 534
Reputation: 41706
Andy,
SDN only checks for modifications of the set, aka additions and removals, it doesn't check each of the relationships for a change, that would be even more costly.
Usually that can be solved by saving the relationship via a repository or template instead of adding it to a set and then saving the node. That is also faster.
Upvotes: 1