Skip to content

Changes to entity in BeforeSaveCallback not being applied to generated SQL #902

@alimac87

Description

@alimac87

Hi,

I'd tried to use a BeforeSaveCallback to change an immutable entity before saving to the database (specifically to set a String id attribute). However after returning a new version of the entity from a BeforeSaveCallback, the generated insert statement doesn't include the ID column:
INSERT INTO "LEGO_SET" ("MAX_AGE", "MIN_AGE", "NAME") VALUES...

I've reproduced the issue by modifying the LegoSet example to use a BeforeSaveCallback: alimac87/spring-data-examples@924e779

With these changes, running AggregateTests:exerciseSomewhatComplexEntity errors out on the first call to repository:save (I've made the ID columns NOT NULL to highlight the issue).

It may be that I'm mis-understanding and/or mis-using the BeforeSaveCallback in some way - apologies in advance if that's the case.

Some things I've tried:

  • Within the BeforeSaveCallback setting the entity ids by mutating the entity does work, however in my production code the preference is for immutable objects (which I think using BeforeSaveCallback should support, at least if I'm reading point 3 of this comment correctly?)
  • Debugging through the code I see JdbcAggregateTemplate.store does update the aggregateRoot on the MutableAggregateChange (line 335), but does not appear to update the entity contained within the DbAction.InsertRoot within the MutableAggregateChange - it appears it's the DbAction which is later used to build the INSERT statement.
  • I can avoid the issue by using JdbcAggregateTemplate.insert directly

Thanks,
Ali

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: invalidAn issue that we don't feel is valid

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions