Hibernate - Envers - Multiple audit targets
I am already using Hibernate Envers to audit objects that are updated by the user through the interface; however, I also have asynchronous jobs running in the background and I would like to check them with Envers as well. Now, for the UI, I keep track of which HttpRequest made the change that gives me the date, user, session, etc. For background jobs, I would like to keep track of the due date of the job, as well as the exact job that modified it (job class).
Is it possible to set 2 audit objects, 1 for user interface and 1 for system changes?
Walter
I haven't tested this yet, but I just do 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 to set those properties. Now I should be able to track how the entity has changed, if the user made a change (and what request it is attached to), or if the system has changed the entity, what work is responsible for the change. I would store more properties in SystemRevision than most likely the arguments and method name.