cancel
Showing results for 
Search instead for 
Did you mean: 

Join the community at Nodes 2022, our free virtual event on November 16 - 17.

Unable to save createdby and updatedby in spring boot 2.3.5

kapilarora5988
Node Link

I am unable to save createdby and updatedby in spring boot neo4j in spring boot 2.3.5. i have annotated them with CreatedDate, CreatedBy, LastModifiedBy, LastModifiedDate and used spring data annotation of prepersist and preupdate but nothing is happening

1 ACCEPTED SOLUTION

gerrit_meier
Neo4j
Neo4j

Spring Data Neo4j does not support the JPA annotations for prepersist and preupdate. You would provide the username by implementing the AuditorAware interface:

class MyUserProvider implements AuditorAware<String> {

  public Optional<String> getCurrentAuditor() {
    return Optional.of("MyUserName");
  }
}

This also helps to separate the logic for auditing and user resolution from your domain model.

See https://docs.spring.io/spring-data/neo4j/docs/5.3.x/reference/html/#auditing.auditor-aware for more information.

View solution in original post

4 REPLIES 4

gerrit_meier
Neo4j
Neo4j

Did you enable the auditing feature for Spring Data Neo4j?

I did enable it @EnableNeo4JAuditing. I am using these annotations to update the createdby and updatedby while with the above auditing annotation it was updating the createdAt and updatedAt but not the by ones.

gerrit_meier
Neo4j
Neo4j

Spring Data Neo4j does not support the JPA annotations for prepersist and preupdate. You would provide the username by implementing the AuditorAware interface:

class MyUserProvider implements AuditorAware<String> {

  public Optional<String> getCurrentAuditor() {
    return Optional.of("MyUserName");
  }
}

This also helps to separate the logic for auditing and user resolution from your domain model.

See https://docs.spring.io/spring-data/neo4j/docs/5.3.x/reference/html/#auditing.auditor-aware for more information.

Thanks @gerrit.meier it helped me more to be switching to neo4j.