Deep Composition. Error after saving Entities

Hello everyone,
I have such structure of Entities Patient->Diagnosis; Patient->Event->Relapse; Patient->Therapy->Protocol; Patient->Therapy->Tc_99 and so on. All connected Entities are edited on the same screen. I look equals topics, but don’t find anything useful.
My datasource looks like:

<dsContext>
        <datasource id="patientDs"
                    class="com.company.pandora.entity.Patient"
                    view="patientFullViewe">
            <datasource id="diagnosDs"
                        property="diagnos"/>
            <datasource id="treatmentDs"
                        property="treatment">
                <datasource id="ear_ratingDs"
                            property="ear_rating"/>
            </datasource>
            <datasource id="therapyDs"
                        property="therapy">
                <datasource id="protocolDs"
                            property="protocol"/>
                <datasource id="tc99_scintigraphyDs"
                            property="tc99_scintigraphy"/>
                <datasource id="myelogramDs"
                            property="myelogram"/>
            </datasource>
            <datasource id="eventDs"
                        property="event">
                <datasource id="relapseDs"
                            property="relapse"/>
            </datasource>
            <datasource id="surgeryDs"
                        property="surgery"/>
        </datasource>
    </dsContext>

I create objects in controller:
> @Override

        protected void initNewItem(Patient item) {
            item.setDiagnos(metadata.create(Diagnosis.class));
            item.setTherapy(metadata.create(Therapy.class));
            item.setSurgery(metadata.create(Surgery.class));
            item.setTreatment(metadata.create(TreatmentRating.class));
            item.setEvent(metadata.create(Event.class));
            item.getEvent().setRelapse(metadata.create(Relapse.class));
            item.getTreatment().setEar_rating(metadata.create(EarRating.class));
            item.getTherapy().setProtocol(metadata.create(Protocol.class));
            item.getTherapy().setTc99_scintigraphy(metadata.create(Tc99Scintigraphy.class));
            item.getTherapy().setMyelogram(metadata.create(Myelogram.class));
        }

When I click OK, I see the following error:
23

Well, I solve this problem.

And answer is here:

I should just add my related entities to DsContext like this:

@Override
protected void postInit() {
getDsContext().addBeforeCommitListener(context → {
context.getCommitInstances().add(getItem().getEvent().getRelapse());
context.getCommitInstances().add(getItem().getTherapy().getProtocol());
context.getCommitInstances().add(getItem().getTherapy().getTc99_scintigraphy());
context.getCommitInstances().add(getItem().getTherapy().getMyelogram());
context.getCommitInstances().add(getItem().getTreatment().getEar_rating());
});
}