开发者

Envers with Hibernate Interceptors, onDelete

I'm trying to implement a simple Envers + interceptor based approach to audit my Hibernate entities. For this, as per the typical approach, there's a BaseEntity with all the audit properties:

BaseEntity{
    createdOn;
    createdBy;
    updatedOn;
    updatedBy;
}

In the AuditInterceptor, I have overridden onFlushDirty and onSave methods to manipulate the above properties depending upon whether it's an entity Save or Update. Everything works as expected for Save and Update.

The issue that I'm facing is: I need a way to be able to manipulate the above properties for Delete operations as well. Overriding onD开发者_开发技巧elete does give me a handle to the state[] array, but modifying it doesn't reflect in the _AUD (audit) tables. In a nutshell: I want to be able to audit delete operations in the audit tables as well.

Is there a workaround for this, or am I missing something?


I don't think you need to implement the onSave, onFlushDirty methods.

You just need to implement the RevisionListener interface. If you follow the pattern here you don't need to add those properties (createdOn etc) to your entities either (unless you need them for normal operations).

See http://docs.jboss.org/hibernate/envers/3.6/reference/en-US/html_single/#revisionlog for more details. In the example here they are using Seam to get the logged in user.

Envers allow you to separate your auditing from your entities which keeps your normal model clean and minimises the code required to do the auditing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜