Skip to content
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

Persistable implementation not carrying is-new state forward for immutable types #77

Closed
odrotbohm opened this issue Nov 25, 2021 · 0 comments
Assignees
Labels
module: bytebuddy ByteBuddy plugin type: enhancement New feature or enhancement to an existing one
Milestone

Comments

@odrotbohm
Copy link
Member

When aggregates are designed to be effectively immutable, e.g. by providing with…(…) methods, the state of the synthetic is-new flag introduced via the ByteBuddy plugin is not transferred to the fresh instance created as the user code doesn't know about it.

@AllArgsConstructor // Gets this.__jMolecules_isNew = true; added
class Sample {

  private final UUID id;
  private final Status status;

  // Generated:
  // private @Transient boolean __jMolecules_isNew = true; <- generated

  Sample(Status status) {

    this.id = UUID.randomUUID();
    this.status = status;
    
    // Generated:
    // this.__jMolecules_isNew = true; 
  }

  Sample withStatus(Status status) {
    return new Sample(this.id, status);
  }

  // Generated:
  // @PrePersist
  // @PostLoad
  // void markNotNew() {
  //   this.__jMolecules_isNew = false;
  // }
}

Imagine a Sample instance created and persisted. It'll end up with the is-new flag set to false. Calling withStatus(…) however will result the new instance that is effectively considered the same aggregate (same identifier) but has the is-new flag reset to true.

A first attempt to solve the problem might be to attach to the wither convention and post process object instances returned for those to transfer the flag if the type returned is the current type or a specialized flavor of it.

@odrotbohm odrotbohm added type: enhancement New feature or enhancement to an existing one module: bytebuddy ByteBuddy plugin labels Nov 25, 2021
@odrotbohm odrotbohm added this to the 0.6 milestone Nov 25, 2021
@odrotbohm odrotbohm self-assigned this Nov 25, 2021
odrotbohm added a commit that referenced this issue Nov 25, 2021
We now also intercept wither methods to transfer the is-new state of the current instance to the one returned from the method.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: bytebuddy ByteBuddy plugin type: enhancement New feature or enhancement to an existing one
Projects
None yet
Development

No branches or pull requests

1 participant