In my engagement to clone an Aggregate with an Entity I failed somewhat.
java.lang.IllegalStateException: Cannot register new aggregate. This entity is already part of another aggregate
here is what I do:
newRecipe = new Recipe(oldRecipe)
In Recipe.ctx() I have bunch of Entities:
map= Map // which I copy in the same way with CopyConstructor pattern
And this is why the “This entity is already part of another aggregate” happens.
it seems that i must instance a new ENTITY only after an apply()?
But this means that I can not use a single event to bear all data to be cloned but, need apply() a bunch of IngredientInserted events after the clone command.
I’d prefer one clean single Event starting up my cloned Recipe.
What do you think?