# Issue with Node Persistence: Actor Node Updated When Movie Node is Updated

**URL:** <https://community.neo4j.com/t/issue-with-node-persistence-actor-node-updated-when-movie-node-is-updated/72776>\
**Category:** Spring Data Neo4j & Neo4j-OGM\
**Tags:** spring-data-neo4j--n\
**Created:** [February 24, 2025, 9:36am UTC](https://community.neo4j.com/t/issue-with-node-persistence-actor-node-updated-when-movie-node-is-updated/72776 "2025-02-24T09:36:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nitinparam356](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/nitinparam356/32/33359_2.png) [@nitinparam356](https://community.neo4j.com/u/nitinparam356)\
**Post date:** [February 24, 2025, 9:36am UTC](https://community.neo4j.com/t/issue-with-node-persistence-actor-node-updated-when-movie-node-is-updated/72776/1 "2025-02-24T09:36:39Z")

</div>

I’m encountering an issue with node persistence in my project. I have two nodes: `Movie` and `Actor` . The `Movie` node has a property of `Actor` . Here’s a simplified version of my code:

```auto
@Node
class Movie {
    String title;
    Actor topActor;
}

@Node
class Actor {
    String name;
}

```

When I create and save a `Movie` and an `Actor` like this:

```auto
Movie movie = new Movie("Polar Express");
Actor actor = new Actor("Tom Hanks");

movie.setTopActor(actor);

```

Both the `Movie` and `Actor` nodes get saved, which is expected.  
However,

```auto
movie.setLength("1:26");

```

when I update the `Movie` node, the `updatedAt` field of both the `Movie` and `Actor` nodes gets updated. I expected only the `updatedAt` field of the `Movie` node to be updated.

Can anyone explain why this is happening and how I can prevent the `updatedAt` field of the `Actor` node from being updated when only the `Movie` node is updated?

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [February 24, 2025, 3:02pm UTC](https://community.neo4j.com/t/issue-with-node-persistence-actor-node-updated-when-movie-node-is-updated/72776/2 "2025-02-24T15:02:02Z")

</div>

How are you updating it? Can you share the code?

Your domain object is the movie node. I assume you are finding it, updating the movie attribute, then saving the movie node. I believe the entire movie node gets recreated, which includes the actor node, when you save. You can see this if you turn on logging. It will log the cypher statements.

---

<div class="post-metadata">

**Author:** ![gerrit.meier](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/gerrit.meier/32/27374_2.png) [@gerrit.meier](https://community.neo4j.com/u/gerrit.meier)\
**Post date:** [February 25, 2025, 7:52am UTC](https://community.neo4j.com/t/issue-with-node-persistence-actor-node-updated-when-movie-node-is-updated/72776/3 "2025-02-25T07:52:51Z")

</div>

The explanation given by @glilienfield is correct. Spring Data Neo4j will traverse through all reachable objects and update them (even if there isn't anything to update). This will update the `updated` values.

You can statically block those updates but would require to take care of the updates of the `Actor` when needed with its own repository.  
The `@Relationship` annotation has a newer property `cascadeUpdates`. If set to _false_, SDN will not process the related entity when you are persisting the class where the relationship is defined. In your case the `Movie` class.

> <https://github.com/spring-projects/spring-data-neo4j/blob/0cc43ecf599f6580be02e857d90c63fe0d40e939/src/main/java/org/springframework/data/neo4j/core/schema/Relationship.java#L93>

---

<div class="post-metadata">

**Author:** ![nitinparam356](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/nitinparam356/32/33359_2.png) [@nitinparam356](https://community.neo4j.com/u/nitinparam356)\
**Post date:** [February 25, 2025, 10:24am UTC](https://community.neo4j.com/t/issue-with-node-persistence-actor-node-updated-when-movie-node-is-updated/72776/4 "2025-02-25T10:24:33Z")

</div>

The issue you're facing is as follows:

```auto
@Node
class Movie {
    String title;
    @Relationship(type = "HAS", direction = Relationship.Direction.INCOMING, cascadeUpdates = false)
    Actor topActor;
}

@Node
class Actor {
    String name;
    @Relationship(type = "HAS", direction = Relationship.Direction.INCOMING)
    private AdditionalDetails additionalDetails;
}

@Node
class AdditionalDetails {
    String address;
    String location;
}

```

In this case, you want to save the `Actor` along with `AdditionalDetails`, so `cascadeUpdates` should be `true` by default. However, when you're saving the `Movie`, the `Actor` is not getting updated because `cascadeUpdates` is set to `false`, but its updating `AdditionalDetails` Why ???  
**Expected behavior** : On `Movie` update Only the `Movie` should be updated.  
On `Actor` update The `Actor` and `AdditionalDetails` both should get updated

---

<div class="post-metadata">

**Author:** ![nitinparam356](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/nitinparam356/32/33359_2.png) [@nitinparam356](https://community.neo4j.com/u/nitinparam356)\
**Post date:** [February 27, 2025, 7:07am UTC](https://community.neo4j.com/t/issue-with-node-persistence-actor-node-updated-when-movie-node-is-updated/72776/5 "2025-02-27T07:07:03Z")

</div>

@gerrit.meier@glilienfield can you help us with the above one
