Auditing

Learn about Spring Data Cassandra’s auditing feature.

The auditing feature in Spring Data Cassandra automatically tracks and maintains metadata about data changes, including creation, modification, and deletion. It enhances data governance, traceability, and accountability in Cassandra-based applications, simplifying the implementation of audit trails.

Auditing metadata in the entity classes

First, let’s add a few properties in the POJOs that map the auditing metadata field in the database.

The Book entity

Let’s add properties like createdBy, dateCreated, updatedBy, and dateUpdated to the Book class. The underlying Spring Data Cassandra will take care of updating the database with the corresponding fields in the book table.

Press + to interact
package com.smartdiscover.model;
import lombok.Data;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.cassandra.core.mapping.Column;
import org.springframework.data.cassandra.core.mapping.PrimaryKey;
import org.springframework.data.cassandra.core.mapping.Table;
import java.util.Date;
import java.util.UUID;
@Data
@Table
public class Book {
@PrimaryKey
private UUID id;
@Column
private String name;
@Column
private String summary;
@CreatedBy
private String createdBy;
@CreatedDate
private Date dateCreated;
@LastModifiedBy
private String updatedBy;
@LastModifiedDate
private Date dateUpdated;
@Override
public String toString() {
return "Book{" +
"id=" + id +
", name='" + name + '\'' +
", summary='" + summary + '\'' +
", createdBy='" + createdBy + '\'' +
", dateCreated='" + dateCreated + '\'' +
", updatedBy='" + updatedBy + '\'' +
", dateUpdated='" + dateUpdated +
'}';
}
}

Here, we use the Spring Data annotations over the ...