• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

"Upsert" using Container Managed Persistence?

 
Lyn Pierce
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, all -

I'm a little confused about what concurrency control, if any, is built into EJB Container Managed Persistence. I have an application that uses CMP with stateless Entity Beans to access a MySQL database, and I need some information on what I can/should do to protect against colliding database operations. The important points are:

1. This application is the only one that is allowed to access this particular database, but

2. The application is heavily multi-threaded.

Although no two threads *should* be trying to update the same record at the same time, we all know that weird things happen sometimes. So my question is this: how do I perform a serializable "upsert" (update if present, insert otherwise) in this scenario?

Many thanks,
Lyn
 
Shankar Tanikella
Ranch Hand
Posts: 329
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lyn,
If I get the scenario you described correctly, I prefer programmatic control over this i.e. I shall verify if the record is available for my unique key in the DB and do an update operation if already existing or else create one - all this at my data access layer. However, if you need some rules to manage your concurrency, links here and here would/should help you do that. But personally i do not like using so called "locks" until and unless it is really necessary.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic