How to get parent entity instance while editing the child entity (1:1 Composition)?

Hello,

could you advise me please, how to get the parent entity in this scenario:

  • Parent - child,
  • @Composition,
  • @OneToOne(fetch = FetchType.LAZY, optional = false)
  • The owning side is the parent.

I am editng the child in a editor screen, and then I am in a child controller.
I need some data from the parent… How to get it?

Something like “getEditedEntity().getParent()

Thank you very much in advance…
Tomas

Hi Tomas!

If you are opening the ChildEditScreen from the ParentEditScreen, the easiest way to provide the parent entity to the child controller is to pass it as a parameter.
Doc link: Opening Screens :: Jmix Documentation.

Otherwise, there is no easy way to get the parent entity. Standard loads only. Because owning side is with the parent.

Regards,
Dmitriy

1 Like

Yes, it works.
Thank you.
T

@Install(to = "photoField.entityOpenComposition", subject = "screenConfigurer")
    private void photoFieldEntityOpenCompositionScreenConfigurer(final Screen screen) {
        ((PhotoEdit) screen).setProviderApplicationId(getEditedEntity().getProviderApplicationId());
    }