Skip to content

Spring Data JDBC Auditing when using MappedCollection #2027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mattmcc-attest opened this issue Apr 11, 2025 · 1 comment
Closed

Spring Data JDBC Auditing when using MappedCollection #2027

mattmcc-attest opened this issue Apr 11, 2025 · 1 comment
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@mattmcc-attest
Copy link

I have an Entity where I am using Auditor fields createdBy and updatedBy

public record Parent(
    @Id UUID id,
    String title,
    @MappedCollection(idColumn = "parent_id") Set<Child> children,
    @CreatedBy UUID createdBy,
    @LastModifiedBy UUID updatedBy)

If I add the auditor fields on to the nested entity:

public record Child(
    @Id @Column("id") UUID id,
    UUID parentId,
    String name,
    @CreatedBy UUID createdBy,
    @LastModifiedBy UUID updatedBy)

they aren't populated when being insert into the database.

Is there no way this data can be propagated into the nested entities? Is this due to the simpler model JDBC uses over JPA?

If so, is there any recommendations on what to do instead?

I was thinking of adding them manually into the nested entities in my code.. at that stage I might as well add them to the root entity anyway and get rid of the Auditor altogether to be consistent.

Thanks!

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 11, 2025
@schauder
Copy link
Contributor

schauder commented Apr 14, 2025

This is a duplicate of #1899

If you want auditing information or similar on nested entities the aggregate root should maintain this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants