Audits with Spring Data Neo4j

后端 未结 2 1617
醉话见心
醉话见心 2021-01-07 04:42

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

相关标签:
2条回答
  • 2021-01-07 05:16

    Spring Data Neo4j (SDN) introduced the concept of lifecycle events in version 2.1. This will also work for cascaded entities.

    0 讨论(0)
  • 2021-01-07 05:34

    Since Spring Data Neo4j 2.2, we can use the AuditingEventListener for the auditing of entities. Spring Data 1.5 offers the @CreatedDate, @CreatedBy, @LastModifiedDate and @LastModifiedBy 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()));
        }
    
    }
    
    0 讨论(0)
提交回复
热议问题