Unable to avoid: com.vaadin.ui.UIDetachedException

Hi,

I just started using vaadin and walked through the tutorials. I translated the “Customer Grid tutorial” to Spring boot and added JPA to my application. Everything works smoothly. Now, I wanted to use the @Push feature to refresh the grid whenever my JPA persists something. I registered my MainUI.class as as an EntityListener and added the following method to the MainUI.class:

[code]
@PrePersist
public void customerPrePersist(Customer customer){
// We cannot use the injected repository so get it like this
CustomerRepository repo = BeanUtil.getBean(CustomerRepository.class);

    final MainUI ui = MainUI.this;
    logger.info("Persisted customer: " + customer.toString());
    //ui.access(()->{
    ui.accessSynchronously(()->{
        if (ui.isAttached()){
            List<Customer> customers = repo.findAll();
            grid.setItems(customers);
        };
    });
}

[/code]However, I always encounter the following exception:
com.vaadin.ui.UIDetachedException: null
at com.vaadin.ui.UI.accessSynchronously(UI.java:1408) ~[vaadin-server-8.0.6.jar:8.0.6]

I hope you have an idea what I could do to avoid this.

Best wishes,
Simon