Cambridge Technology PartnersCommunity Documentation

Chapter 6. Auditing

6.1. Activating Auditing
6.2. Using Auditing Annotations
6.2.1. Updating Timestamps
6.2.2. Who's Changing My Entities?

A common requirement for entities is tracking what is being done with them. CDI Query provides a convenient way to support this requirement.


CDI Query does not support creating revisions of entities. If this is a requirement for your audits, have a look at Hibernate Envers.

CDI Query uses an entity listener to update auditing data before entities get created or update. The entity listener must be activated before it can be used. This can either be done globally for all entities of a persistent unit or per entity.

Activation per persistence unit:

<entity-mappings xmlns=""
        xsi:schemaLocation="" version="2.0">
                <entity-listener class="com.ctp.cdi.query.audit.AuditEntityListener" />

Activation per entity:


public class AuditedEntity implements Serializable {

All that has to be done now is annotating the entity properties which are used to audit the entity.