I’ve got a question. I’ve got an Manifest entity with an association to a Statusupdate entity.
In the Manifest-edit-screen, I have a button for opening a Statusupdate create screen, to create a Statusupdate.
When a Statusupdate gets created, a Statusupdate Entitylistener modifies the manifest, and changes the status of the manifest.
The problem occurs when I have a Statusupdate create screen, in which I also need to adjust attributes of the manifest.
After submitting the Statusupdate, and before returning to the manifest-edit screen, the Statusupdate entity listener triggers and adjusts the manifest.
When I press OK on the manifest edit screen, I get the notification “Object Manifest was modified in another transaction”, which makes sense, since the Manifest got an update by the Statusupdate EntityListener.
But although it makes sense, I can’t seem to work out a solution. I can’t make an exception in the listener since I need the logic there.
I’m pretty new to Java and Java persistence, so I’m not really experienced enough with the core details on persisting, transactions etc to work out a solution myself.
First of all, you should create the Manifest instance when clicking ‘Create’ - it will be created automatically. When you want to edit selected entity you also should not create a new instance:
public://attachments/5fee89f9d3e27f5d5112861a10037a60.png
Secondly, you should use EntityManager.merge(manifest) in the StatusLogListener:
I can’t really lead back the code in the first step, I think it’s some experimental code that I forgot to clean out for this example. In our case, the create button will be left out since we only expect input from the API.
However, I followed your guide, and I got it to work. Thanks allot for that! That really was an issue in our project, so I’m glad with your help. I see you’re on fire on the forums btw, props for that