fix: #534 added support for @CreatedDate in Datastore #4276
+24
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.