Thank you for the explanation and test project.
This is not the case for compositions. The composition items (Perso and Conta) will go to the database only when you save the root entity (Adres). The whole point of compositions is editing aggregates in memory and saving them in a single transaction. See Editing Aggregates.
To get a list of persons in the Conta detail view, pass it from the Adres detail view instead of loading from the database:
- Remove loader from persoDC:
<collection id="persoDC" class="com.company.saveentity.entity.Perso" />
- Add setter to ContaDetailView:
public class ContaDetailView extends StandardDetailView<Conta> {
@ViewComponent
private CollectionContainer<Perso> persoDC;
public void setPersons(Collection<Perso> persons) {
persoDC.setItems(persons);
}
}
- Invoke it for Conta create and edit actions in AdresDetailView:
public class AdresDetailView extends StandardDetailView<Adres> {
@Install(to = "contaDataGrid.create", subject = "viewConfigurer")
private void contaDataGridCreateViewConfigurer(final ContaDetailView contaDetailView) {
contaDetailView.setPersons(getEditedEntity().getPerso());
}
@Install(to = "contaDataGrid.edit", subject = "viewConfigurer")
private void contaDataGridEditViewConfigurer(final ContaDetailView contaDetailView) {
contaDetailView.setPersons(getEditedEntity().getPerso());
}
}
Attached the whole project:
SaveEntity-fixed.zip (2.3 MB)
Regards,
Konstantin