Use custom logic for creating an entity

Hello,
I have the following issue:
I have an entity A with a list of other entities B. In the edit screen of A, I want to display the list of Bs. Creating Bs requires custom logic (calling a service). When creating one B, two Bs need to be created.
What would be the correct approach here?

In the edit screen of B, I have overridden the onWindowCommitAndClose method. There, I invoke my logic and save the two new Bs. After closing the dialog, I want to see the two Bs in the list.

Thank you very much, Reini

Hello,

Your description resembles the implementation of composition in Jmix.

Composition:
https://docs.jmix.io/jmix/data-model/entities.html#references

An example of composition is creating the addition of pets when creating an owner.

Owners → Create Owner
image

Pets tab → Create Pet
image

Jmix Pet Clinic:
https://demo.jmix.io/petclinic/#main/8/owners

Regards,
Nikita