Save Entitiy when detailscreen closed

I have adresses with persons as composition ( each adress has several persons who are working at this adress ).

If I add a person in the Detailscreen and Close the screen
<button id="saveAndCloseBtn" action="saveAction"/>
the entity is NOT saved.

Even when I add

public void onBeforeClose(final BeforeCloseEvent event) {
	  dataContext.save();
}

nothing is saved.

What do I miss ?

Thank you for any help.

Felix

It’s hard to say anything without seeing your code.
Please provide a test project with the entities and views.

Regards,
Konstantin

Hi Konstantin

Attached you find the requested project.

  1. Create an adres

  2. Save this adres with OK

  3. Edit this newly created adres

  4. Create Person, confirm OK

  5. → After entering the name and pressing the OK Button in the persoDetailView this entity should be stored

  6. Create Contact

  7. → Because the Person is not stored in the database, it is not possible to store the new contact with this new person ;/

Thank you for trying to understand the “issue”.

Best regards

Felix

SaveEntity.zip (2.3 MB)

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

Thank you a lot for your explanations and the project.

As I might convert an existing application with a different approach; would it be possible to execute from the perso.onSaveAndCloseButtonClick() the adres.SaveAndCloseButtonClick() ?

Regards
Felix