Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何停止审核hibernate环境中的创建操作?_Hibernate_Spring Boot_Hibernate Envers - Fatal编程技术网

如何停止审核hibernate环境中的创建操作?

如何停止审核hibernate环境中的创建操作?,hibernate,spring-boot,hibernate-envers,Hibernate,Spring Boot,Hibernate Envers,我只想审核更新和删除操作,但hibernate envers也会记录插入操作,我们如何停止审核插入操作 应用程序属性 spring.jpa.properties.org.hibernate.envers.default_catalog=demo_audit spring.jpa.properties.org.hibernate.envers.store_data_at_delete=true spring.jpa.properties.hibernate.listeners.envers.aut

我只想审核更新和删除操作,但hibernate envers也会记录插入操作,我们如何停止审核插入操作

应用程序属性

spring.jpa.properties.org.hibernate.envers.default_catalog=demo_audit
spring.jpa.properties.org.hibernate.envers.store_data_at_delete=true
spring.jpa.properties.hibernate.listeners.envers.autoRegister=false
spring.jpa.properties.hibernate.envers.autoRegisterListeners=false

您需要通过events=>中断envers,查找条件审核的详细描述。 这些步骤适用于spring boot:

  • 重写onPostInsert方法
  • 您需要将自定义的onPostInsertListener注册到envers:
  • Edit1:仅当父实体没有审核的子实体时,此选项才有效。否则,将在创建后添加更新的语句。 因此,我也需要一个答案


    Edit2:检查此手动触发器以获取审核条目-

    您需要通过事件中断envers=>查看条件审核的详细说明。 这些步骤适用于spring boot:

  • 重写onPostInsert方法
  • 您需要将自定义的onPostInsertListener注册到envers:
  • Edit1:仅当父实体没有审核的子实体时,此选项才有效。否则,将在创建后添加更新的语句。 因此,我也需要一个答案

    Edit2:检查此手动触发器以获取审核条目-

    package com.example.stackoverflow1.audit;
    
    import com.example.stackoverflow1.model.Soup;
    import org.hibernate.envers.boot.internal.EnversService;
    import org.hibernate.envers.event.spi.EnversPostInsertEventListenerImpl;
    import org.hibernate.event.spi.PostInsertEvent;
    
    public class CustomAuditEventListenerPostInsert extends EnversPostInsertEventListenerImpl {
    
    
        public CustomAuditEventListenerPostInsert(EnversService enversService) {
            super(enversService);
        }
    
        @Override
        public void onPostInsert(PostInsertEvent event) {
            // super.onPostInsert(event); if this is called, the audit is executed.
            // without it there is no audit entry
        }
    
    }
    
    
    import lombok.AllArgsConstructor;
    import org.hibernate.envers.boot.internal.EnversService;
    import org.hibernate.event.service.spi.EventListenerRegistry;
    import org.hibernate.event.spi.EventType;
    import org.hibernate.jpa.HibernateEntityManagerFactory;
    import org.springframework.stereotype.Component;
    
    import javax.annotation.PostConstruct;
    
    @Component
    @AllArgsConstructor
    public class AuditConfig {
    
        private HibernateEntityManagerFactory hibernateEntityManagerFactory;
    
        @PostConstruct
        public void registerEnversListeners() {
            EnversService enversService =
                    hibernateEntityManagerFactory
                            .getSessionFactory()
                            .getServiceRegistry()
                            .getService(EnversService.class);
    
            EventListenerRegistry listenerRegistry = hibernateEntityManagerFactory.getSessionFactory().getServiceRegistry().getService(EventListenerRegistry.class);
            listenerRegistry.setListeners(EventType.POST_INSERT, new CustomAuditEventListenerPostInsert(enversService));
        }
    }