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

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

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"/commerce-legacy/>
	<ref bean="objectDeletedEntityListener"/commerce-legacy/>
	<ref bean="changeSetPersistenceListener"/commerce-legacy/>
	<ref bean="persistablePostLoadListener"/commerce-legacy/>
	<ref bean="auditEntityListener"/commerce-legacy/>    <!-- Must also be registered in the PersistenceEngine -->

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

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

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="persistenceEngine" ref="persistenceEngineTarget" />
    <property name="auditableClasses">
    <property name="auditDao" ref="auditDao" />
    <property name="metadataMap" ref="persistenceListenerMetadataMap"/commerce-legacy/>

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.