Lukasz Stelmach
Lukasz Stelmach

Reputation: 5391

Setting last update time on node in Neo4j

I would like to update lastUpdate field in node each time some property is change.

Is there is some general solution for it from Neo4j level or Spring Data?

The problem is that our structure and code exsist and these feature has to be added. We use in application Spring Data (ver. 3.1.1) with Aspects. As I see it now I have to change:

I wonder if there is some simpler method that these steps.

Upvotes: 2

Views: 969

Answers (1)

Stefan Armbruster
Stefan Armbruster

Reputation: 39925

You can use a TransactionEventHandler. In your case use the beforeCommit method, iterate over the the changed properties in that transaction using TransactionData.assignedNodeProperties() and set the lastUpdate on the given to current timestamp.

TransactionEventHandler are a sharp tool, be very careful to keep the impact as small as possible.

Upvotes: 1

Related Questions