During synchronization a new object was found through a relationship

Hello all, I am having a bit of trouble.

I have an entity called “Opportunity” it has a composition attribute called “Logistics”

The entity Logistics also has a composition attribute called “delegate”

If you Create a new Opportunity, then Create a new Logstics, then create a new Delegate and try to save.

The following error is thrown.

IllegalStateException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST: com.company.ericssonapp.entity.Logistic-?(05d53f8f-ec30-995c-3774-b5e838ee717c) [new].

The error is not thrown as long as the Logistics AND Opportunity screens are saved before going back and adding Delegates

What is the best way not to receive this error?

Hi Thomas,

can you share the opportunity-edit.xml, logistics-edit.xml and the views.xml so we can have a closer look?

It seems to be a problem with the view definition and usage.

Bye,
Mario

1 Like

Sure. Thanks for your help!

logistic-edit.xml (14.2K)

opportunity-edit.xml (9.3K)

views.xml (4.6K)

You have 2-levels of composition, so please try to follow the rules explained here.

Your opportunity-edit.xml should contain a nested datasource for the collection of Delegate:


<datasource id="opportunityDs"
            class="com.company.ericssonapp.entity.Opportunity"
            view="opportunity-edit">
    <collectionDatasource id="logisticFormDs"
                          property="logisticForm">
        <collectionDatasource id="delegatesDs"
                              property="delegate"/>
    </collectionDatasource> 
...
</datasource>

This datasource seems useless, but in fact it is needed to properly save the second composition.

See also the more broad description why this error occurs in this topic: https://www.cuba-platform.com/discuss/t/relationship-that-was-not-marked-cascade-persist

2 Likes

That worked! Thanks for the help. It was almost too easy.