Note that there are some explanatory texts on larger screens.

plurals
  1. POSDN save nodes and update properties on attached relationships
    primarykey
    data
    text
    <p>We are using spring-data-neo4j release 2.2.2.Release and Neo4j 1.9</p> <p>Saving and updating nodes (properties) works fine using a GraphRepository</p> <p>Our most simple example looks like this:</p> <pre><code>public interface LastReadMediaRepository extends GraphRepository&lt;Neo4jLastReadMedia&gt; {} </code></pre> <p>We also set some relationships connected to a node, the node class looks like this</p> <pre><code>@NodeEntity public class Neo4jLastReadMedia { @GraphId Long id; @JsonIgnore @Fetch @RelatedToVia(type = "read", direction = Direction.OUTGOING) Set&lt;LastReadMediaToLicense&gt; 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&lt;LastReadMediaToLicense&gt; getLicenseReferences() { return licenseReferences; } @Override public String toString() { return "Neo4jLastReadMedia [id=" + id + "]"; } } </code></pre> <p>Now, we save a node using the repository's <code>save()</code> method. The relationships are saved, too, at least for the first <strong>save</strong>.</p> <p>Later when we want to change properties on a relationship (<strong>update</strong> a relationship) that already exists (e.g. lastAccess) we retrieve the node from the database, manipulate its relationship Set, here <code>Set&lt;LastReadMediaToLicense&gt; licenseReferences;</code> and then, try to save the node back with <code>save()</code></p> <p>Unfortunately, the relationship is not updated and all properties remain the same...</p> <p>We know how to do that using annotated cypher queries in the repo, but there has to be an "abstracted" way?!</p> <p>Thanks a lot!</p> <p>Regards</p> <p><strong>EDIT:</strong> 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?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload