[DATAGRAPH-1212] Neo4jAuditing not work because of early ID generation Created: 22/Mar/19 Updated: 29/Mar/19
|Project:||Spring Data Neo4j|
|Affects Version/s:||5.2 M2 (Moore), 5.1.5 (Lovelace SR5)|
|Remaining Estimate:||Not Specified|
|Time Spent:||Not Specified|
|Original Estimate:||Not Specified|
We're trying to use auditing features via @EnableNeo4jAuditing. For our entity classes, we have a common base class (abstract because we don't want it to appear in the label hierarchy):
When calling Neo4jSession#save, the Neo4jAuditingEventListener is called automatically as expected and internally calls IsNewAwareAuditingHandler#markAudited, which then calls Neo4jPersistentEntity#isNew to decide whether the entity should be marked as created (AuditingHandler#markCreated) or as modified (AuditingHandler#markModified).
The way SDN is initialised via Neo4jAuditingRegistrar, Neo4jPersistentEntity#isNew uses the IsNewStrategy implemented in Neo4jPersistentEntity.Neo4jIsNewStrategy#isNew which is not working because it makes its decision based on whether the entity has an id assigned - which is happening automatically before any event listener is called (SaveEventDeleage#preSaveCheck -> SaveEventDelegate#visit -> MappingContext#nativeId -> MappingContext#generateIdIfNecessary).
We found two workarounds which are neither documented nor nice but I'm adding them here in case anyone else runs into this issue:
I would be happy to create a pull request but I'm not sure what's the preferred way to solve the problem:
|Comment by nioertel [ 22/Mar/19 ]|
I also added a small project with unit tests to reproduce the issue.
|Comment by nioertel [ 29/Mar/19 ]|
Just realised that I created a duplicate to DATAGRAPH-1185.