Skip to content

Conversation

@mehdi0933
Copy link

This PR resolves issue #534 where @CreatedDate was not being correctly populated in Datastore entities.

The root cause was that the DatastoreAuditingEventListener was only calling markModified on the auditing handler, which indiscriminately updates modification dates but often misses the initial creation signal for new entities.

Changes
Modified DatastoreAuditingEventListener to include DatastoreMappingContext via constructor injection.

Updated onApplicationEvent logic to use persistentEntity.isNew(entity) to distinguish between "insert" and "update" operations.

The listener now calls handler.markCreated(entity) for new entities (filling both @CreatedDate and @LastModifiedDate) and handler.markModified(entity) for existing ones.

Fixed Java Generics warnings by using Iterable<?> for entity iteration.

Impact
Users can now use the standard Spring Data @CreatedDate annotation on their Datastore entity fields to automatically track when a record was first persisted.

Validation performed
Compiled the module successfully using mvn clean compile -pl spring-cloud-gcp-data-datastore.

Verified that the logic correctly identifies new entities using the provided MappingContext.

@mehdi0933 mehdi0933 requested a review from a team as a code owner January 7, 2026 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant