Unable to invoke method click in com.vaadin.shared.ui.button.ButtonServerRpc


I have a Many-To-Many relation between Transaction and Payment. Now in transaction date I need to set Last Payment date. I have the following code:

 paymentDs.addCollectionChangeListener(event -> {
            List<Payment> list = event.getItems();
            log.info("Datasource {} content has been changed due to ...." + event.getOperation());
            log.info("Datasource listsize=" + list.size());
            if (list.size() > 0) {

              Payment payment = list.get(0);   
                maxDate = payment.getDate();

                log.info("MAXDATe=" + maxDate);


Unfortunately when I select a new payment(through paymentTokenList) I have an error"

IllegalStateException: Cannot get unfetched attribute [transactions] from detached object com.company.crmrai.entity.Payment-253de322-9404-8dc4-c5db-4ec4c88f2ba4 [detached].

and this log file

2019-02-05 10:51:48.662 INFO  [http-nio-8080-exec-10/app/admin] com.company.crmrai.web.transaction.TransactionEdit - MAXDATe=Tue Feb 12 00:00:00 EET 2019
2019-02-05 10:51:48.687 ERROR [http-nio-8080-exec-10/app/admin] com.haulmont.cuba.web.log.AppLog - Exception in com.haulmont.cuba.web.toolkit.ui.CubaButton: 
com.vaadin.server.ServerRpcManager$RpcInvocationException: Unable to invoke method click in com.vaadin.shared.ui.button.ButtonServerRpc
	at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:160) ~[vaadin-server-7.7.15.cuba.3.jar:7.7.15.cuba.3]
	at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:119) ~[vaadin-server-7.7.15.cuba.3.jar:7.7.15.cuba.3]

Caused by: java.lang.reflect.InvocationTargetException: null
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_201]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_201
aused by: com.vaadin.event.ListenerMethod$MethodException: Invocation of method buttonClick in com.haulmont.cuba.web.gui.components.WebButton$$Lambda$111/1244291937 failed.

If I press Cancel and Ok (Save) it works.
How could I avoid this error?

Most likely, there is an error in your code: you are loading data with view that does not include transactions relation.

Read more about reasons of unfetched attribute errors here: Views - the uncharted mystery – Road to CUBA and beyond...

Thank you Yuriy.
Indeed I made a new view in Payment - payment-with-transaction view and I attached in payment-browse.xml.
But now I have another error when I select a payment:

ArrayIndexOutOfBoundsException: Array index out of range: 0