| Author |
"Upsert" using Container Managed Persistence?
|
Lyn Pierce
Greenhorn
Joined: Nov 10, 2011
Posts: 3
|
|
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
Joined: Jan 30, 2011
Posts: 329
|
|
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.
|
Have Fun with Java
little,little.. little by little makes a lot..
|
 |
 |
|
|
subject: "Upsert" using Container Managed Persistence?
|
|
|