Hello,
I've written a TransactionEventHandler that creates certain properties on newly created Nodes and Relationships. It also modifies certain existing properties even if those properties have been modified as part of that transaction. For example, I set a modified date stamp and increment a version number on entities that have been modified. This is all done in the beforeCommit() method. The problem is that the modifications to those properties are not persisted.
Putting it more concretely. I add a UUID, version, created date, and updated date property to all entities returned by TransactionData.createdNodes/Relationships(). This part works fine. However, when I receive a modified entity. I don't appear to be able to override the value of any property that is returned from TransactionData.assignedNode/RelationshipProperties(). Take the following code where I try to set an updated time stamp on a modified Node:
Assume that I've iterated over all modified Node properties using TransactionData.assignedNodeProperties() to find all entities (Nodes) associated with the modified properties. I then do:
for (PropertyContainer node: changedNodes) {
node.setProperty("updated_at", formatISO8601Date());
}
I do a similar thing to increment the value of a version stamp.
The problem is that this new value is not persisted. After the transaction has completed, I looked at the affected Nodes and the old values for the "updated_at" property are still there. In fact in debugging this, I put a breakpoint in this code to confirm that this code was in fact being executed. I also put a breakpoint in afterCommit() and saw that the values for those properties were the old values--as if the setProperty() calls in beforeCommit() had no affect.
One more piece of information, the REST driver I'm using (node-neo4j) has a Node.save() method. When a previously-persisted Node is saved, node-neo4j does an update by sending all properties in a .../properties request. So even properties that have not been added or modified are included in this request.
Is it expected behavior that properties that are being modified in a transaction can't be modified in TransactionEventHandler.beforeCommit() method?
Thanks.
-brian