I use Jboss3.2.3 as the EJB container. I am a newbie with EJB, so I am sure my problem must be quite common. Here is the scenario:
I have a CMP bean that reads Purchase Order(PO) information from a database. The information is then passed on to the presentation layer (struts). Everything is fine here.
While I am working on the PO, another user also tries to update the same PO. That user gets the PO from the database and use the CMP bean to update the PO.
The issue is : Because the second user completes the update before I am done, I am working on "old" data then. When I save the PO, I override the changes made by the second user. How do I prevent this scenario from happening or what's the solution?
Well, the best option here is probably to use optimistic concurrency. Read a last-modified timestamp from your CMP and send that up with the rest of the data to Struts. Send it back down, and only update the CMP if the last-modified timestamp is the same.