Audit Log Storage

SAP Commerce persists audit logs for types configured for auditing automatically. It uses a default storage implementation for that purpose.

SAP Commerce provides a JDBC-based implementation of audit storage by default. For each type, a new corresponding table is created during initialization or update. The table name follows the <deploymentName><numericTypeCode>sn naming convention. For example, an audit table for the User type would be called users4sn.

A table for a standard type has the following structure:

Field Name

Type

Description

ID

bigint

Record id

ITEMPK

bigint

Audited instance PK

ITEMTYPEPK

bigint

Audited type PK (ComposedType)

timestamp

datetime

Change timestamp

currenttimestamp

datetime

Audit record timestamp

changinguser

varchar

Author of the change

context

longtext

Additional context (JSON)

payloadbefore

longtext

The whole business payload of audited type before a persistence operation (JSON)

Before INSERT, the payloadbefore is empty.

payloadafter

longtext

The whole business payload of audited type after a persistence operation (JSON).

After DELETE, the payloadafter is empty.

operationtype

bigint

0 - deletion, 1 - creation, 2 - modification

A table for many-to-many-relation types has the same structure, plus three additional columns:

Field Name

Type

Description

sourcePK

bigint

Source item PK

targetPK

bigint

Target item PK

languagePK

bigint

Language PK

When you configure a type for auditing, each persistence operation to the type itself triggers the storing of an audit log. The framework does it automatically on each ModelService#save and ModelService#remove call. It doesn't require any further action or configuration. The following diagram shows the process for storing changes to a type:

An audit log entry is stored immediately after persisting item data itself when there's no active transaction.

In the following diagram, you can see how the same operation works when a transaction is in place:

The transaction is started and within it all operations such as creation, modification, and deletion are performed as in the first diagram. Note that an audit storing action is delayed to the point when the transaction is committed.