Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. The Developer Center continues to support Commerce 6.13.0 through 7.4.1.Visit new site

Enabling object auditing

Enabling object auditing

To enable object auditing, you first need to add the audit entity listener to the list of entity manager lifecycle and persistence engine operation listeners. In the ep-core project, open WEB-INF/conf/spring/dataaccess/openjpa/openjpa.xml and locate the entityManagerLifecycleListeners bean definition. The entityManagerLifecycleListeners definition contains the objects that listen for OpenJPA lifecycle events (creates, updates, etc.). Add the auditEntityListener bean to the entityManagerLifecycleListeners list.

<util:list id="entityManagerLifecycleListeners">
	<ref bean="lastModifiedEntityListener"/>
	<ref bean="objectDeletedEntityListener"/>
	<ref bean="changeSetPersistenceListener"/>
	<ref bean="persistablePostLoadListener"/>
	<ref bean="auditEntityListener"/>    <!-- Must also be registered in the PersistenceEngine -->
</util:list>

Then locate the persistenceEngineOperationListeners list and add the auditEntityListener bean to the persistenceEngineOperationListeners list.

<util:list id="persistenceEngineOperationListeners">
	<ref bean="auditEntityListener"/>  <!--Must also be registered in the EntityManagerFactory-->
</util:list>

Then locate the auditEntityListener bean definition. The auditableClasses property specifies the classes that will be audited. If you want to audit other domain objects, you must add their class names to this list.

<bean id="auditEntityListener" class="com.elasticpath.persistence.impl.AuditEntityListener">
<property name="beanFactory" ref="coreBeanFactory"/>
<property name="auditableClasses">
 <set>
     <value>com.elasticpath.domain.attribute.impl.AbstractAttributeValueImpl</value>
     <value>com.elasticpath.domain.attribute.impl.ProductAttributeValueImpl</value>
     <value>com.elasticpath.domain.attribute.impl.SkuAttributeValueImpl</value>
     <value>com.elasticpath.domain.catalog.impl.DigitalAssetImpl</value>
 </set>
</property>
<property name="nonAuditableNamedQueries">
    <set>  
    <!-- <value></value> -->
    </set>
</property>
<property name="metadataMap" ref="persistenceListenerMetadataMap"/>
</bean>

After making the changes, you must rebuild and redeploy the core library, web applications, and the Commerce Manager.

When auditing is enabled, information related to the changed objects is written to the audit tables in the database.

Note that you can include custom metadata in the audit records. For more information, see Including audit metadata.