Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

CMP Bean and EJB out of synch  RSS feed

 
Vili Leonardo
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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?

Thanks
-Vili
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Kyle
 
Vili Leonardo
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the prompt response. When you say "Read a last-modified timestamp from your CMP", I assume you mean that I have to maintain additional field that has contains the last-modified time stamp?
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup. That's what I meant.

Kyle
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!