@Composition but with automatic save of each edit

The manual states:

Choosing @Composition annotation as the relationship type enables making use of a special commit mode for datasources in edit screens. In this mode, the changes to related instances are only stored when the master entity is committed.

How can I still use composition (because the entity should only exists as a part of the owning entity) but save each sub-entity (e.g. airport terminals) as it is edited / created?

I want to avoid a situation where the user adds and edits a lot of sub-entities and then is at risk of losing a lot of work if they fail to save the main entity.

There is also a calculated field on the main entity screen based on the sub-entities. It is a transient meta-property in the main entity. When I do a refresh on the main entity datasource, it doesn’t refresh this calculation. How do I trigger this recalculation on the field in the fieldgroup?

2 Likes

How can I still use composition (because the entity should only exists as a part of the owning entity) but save each sub-entity (e.g. airport terminals) as it is edited / created?

Just remove @Composition annotation and ignore the theoretical consideration about ownership.

How do I trigger this recalculation on the field in the fieldgroup?

I’m afraid we need a sample project to reproduce the issue and be sure we talk about the same thing.

What happens in the case where I create entity A but do not persist it, then create sub-entity B and persist that, then return to A and end up not saving A. Is that sub-entity B deleted or does it remain, unlinked, floating around?

You will not be able to persist B until A is persisted, because B has a foreign key constraint on A in the database. The solution is to have an additional “Save” button in A editor, so the user will have to save A prior to creating B instances. See an example here (approach 1, ignore the fact that the composition is deeply nested, consider just airports-terminals association).