简体   繁体   English

休眠-启用-多个审核目标

[英]Hibernate - Envers - Multiple Audit targets

I am already using Hibernate Envers to audit entities that are updated by a user through the UI; 我已经在使用Hibernate Envers来审核用户通过UI更新的实体。 however, I also have asynchronous jobs running in the background and would like to audit those as well using Envers. 但是,我也有异步作业在后台运行,并且也想使用Envers来审核它们。 Now, for the UI, I track which HttpRequest made the change which gives me the date, user, session, etc. For the background jobs, I would like to track the date the job was run as well as the exact job that modified it (job class). 现在,对于UI,我跟踪哪个HttpRequest进行了更改,从而为我提供了日期,用户,会话等。对于后台作业,我想跟踪该作业的运行日期以及对其进行修改的确切作业(工作岗位)。

Is it possible to setup 2 Audit entities, 1 for the UI, and 1 for the system changes? 是否可以设置2个审核实体,1个用于UI以及1个用于系统更改?

Walter 沃尔特

I haven't tested this out yet, but I am simply doing the following: 我还没有测试过,但是我只是在做以下事情:

@RevisionListener(SystemRevisionListener.class)
@Entity
public class SystemRevision extends AbstractRevision
{
   @Column(nullable = false, updatable = false)
   protected QuartzTriggerHandle job;

   @Column(nullable = false, updatable = false)
   protected Class jobClass;

   ...
}



@RevisionListener(WebRevisionListener.class)
@Entity
public class WebRevision extends AbstractRevision
{
   @ManyToOne(optional = false)
   @JoinColumn(nullable = false, updatable = false)
   protected HttpRequest httpRequest;

   ...
}

Then, in each listener, I do whatever I need to do to set these properties. 然后,在每个侦听器中,我需要做的所有设置这些属性的事情。 I should now be able to track how an entity as modified, if a user did the change (and what request it is tied into), or if the system changed the entity, what job is responsible for the change. 现在,我应该能够跟踪实体的修改方式,如果用户进行了更改(以及绑定到哪个请求),或者如果系统更改了实体,则由什么工作负责更改。 I would be storing more properties in the SystemRevision than this, most likely the arguments and method name. 我将在SystemRevision中存储比此更多的属性,最有可能是参数和方法名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM