Problems committing changes on an entity

Hi,

for printing different typs of customer receipt for an order-record (example invoice or offer) I defined an own printing screen which is called from the standard cuba list-screen.
Via params map I am passing the GroupDatasource-object to the print-popup.
I am using jasperreport as the reporting-tool and so it is necessary to write informations (for example the date of printing) before the execution of the report can happen, into the order-record and make an GroupDatasource.commit (otherwise it cannot be used in the report).
This is working one time. When the report is done without problems, I want to set an order-field “closed” to true and GroupDatasource.commit once again.
Here is the problem: On the second commit(), I am getting an exception with the info:
Object order was changed from another transaction.

I tried to refresh the groupdatasource after the first commit, but I got the same result.

What is wrong ?

Thanks

Hi,

Such exception is thrown when the object in the database has the version value different from what is saved now. This is how “optimistic locking” works.
When you commit a datasource, the version is incremented and saved to the record if the record contains previous version value, i.e. untouched since loading to the datasource. The saved object is returned and set to the datasource, so it should contain the new version.
Refreshing a collection datasource loads all objects from the database, so they should have recent versions.

You can see what objects are saved and compare their versions with those currently in the database if you set a breakpoint to DataManagerBean.commit() method and look into CommitContext.

Hi Konstantin,
thanks, I found it. I commited the GroupDatasource. The order-record was still the old one.
Using then new order-record from GroupDatasource for the second setting worked.
My mistake.
Thanks for your help.