Skip to content

Spring Data JDBC Auditing when using MappedCollection #2027

@mattmcc-attest

Description

@mattmcc-attest

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!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions