1
votes

I'm trying to setup simple entity audit fields using Spring Data with the annotations from spring-data-commons (e.g. @CreatedDate with type Long as mentioned here http://docs.spring.io/spring-data/commons/docs/current/reference/html/#auditing.annotations)

A solution for Neo4j 2.0 was discussed here: Audits with Spring Data Neo4j. But for version 4, the class seem to have disappeared in the distribution.

I'm assuming an event listener must be added to Neo4j in order for these fields to populate. However I can't find the neo4j counterpart of @EnableMongoAuditing (MongoDB) and @EnableJpaAuditing (JPA) anywhere in the spring-data-neo4j distro.

Does this mean that I have to ignore this particular Spring Data feature on Neo4j? Are there other alternatives?

1
Have you found the solution?Poliakoff

1 Answers

0
votes

@Polyakoff SDN 4 currently does not support annotations from the commons library. To solve this, I had to create a Spring bean listening to the before save event as follows:

@Bean
ApplicationListener<BeforeSaveEvent> beforeSaveEventApplicationListener() {
    return new ApplicationListener<BeforeSaveEvent>() {
        @Override
        public void onApplicationEvent(BeforeSaveEvent event) {
               event.getEntity().setCreatedDate(System.currentTimeMillis());
        }
    };
}