2

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:

  • change behaviour of save() method from GraphRepository
  • change behaviour of Aspect method persist() from node

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you - yes it seems that is what I am looking for.
It was to beautiful to be true ;) - I forget about one - we use REST protocol to connect to Neo4j. And as I see AbstractRemoteDatabase not allow to register any handler. Do you know if it can be handled i some other way?
You cannot do this remotely. The best practice is creating a KernelExtension that registers the tx handler, Max explains this very well at maxdemarzi.com/2015/03/25/triggers-in-neo4j
Wonderful - I've just implement such extension and work like a charm. Thank you.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.