Question: I'm currently working on a project that makes use of Spring Data Neo4j. Whenever a NodeEntity is created, I would like to create a referenced Audit NodeEntity that contains the creation date and user. 

A solution that I've come up with, is to write an AOP Aspect which hooks in on the create method of my service layer. This works fine for entities that aren't cascaded, but what about the cascaded ones? That are not explicitly passed in my service layer so my AOP class will not intercept them. Is there a concept like entity listeners in JPA, or how can I hook into this mechanism?

Answer: 
Since Spring Data Neo4j 2.2, we can use the AuditingEventListener for the auditing of entities. Spring Data 1.5 offers the [@CreatedDate](http://static.springsource.org/spring-data/commons/docs/current/api/org/springframework/data/annotation/CreatedDate.html), [@CreatedBy](http://static.springsource.org/spring-data/commons/docs/current/api/org/springframework/data/annotation/CreatedBy.html), [@LastModifiedDate](http://static.springsource.org/spring-data/commons/docs/current/api/org/springframework/data/annotation/LastModifiedDate.html) and [@LastModifiedBy](http://static.springsource.org/spring-data/commons/docs/current/api/org/springframework/data/annotation/LastModifiedBy.html) annotations. You can use them as follows:

```
@NodeEntity
public class Entity {

    @GraphId
    private Long id;

    @CreatedDate
    private Long date;

}

```

Make sure to configure the AuditingEventListener:

```
@Configuration("db")
@EnableNeo4jRepositories(basePackages = { "your.package" })
@EnableTransactionManagement
public class DatabaseSpringConfiguration extends Neo4jConfiguration {

    @Bean(destroyMethod = "shutdown")
    public EmbeddedGraphDatabase graphDatabaseService() {
        return new EmbeddedGraphDatabase("data/neo4j.db");
    }

    @Bean
    public AuditingEventListener auditingEventListener() throws Exception {
        return new AuditingEventListener(new IsNewAwareAuditingHandler<Object>(isNewStrategyFactory()));
    }

}

```
Spring Data Neo4j (SDN) introduced the concept of [lifecycle events](http://static.springsource.org/spring-data/data-neo4j/docs/2.1.x/reference/html/#d5e1169) in version 2.1. This will also work for cascaded entities.