aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Record Locking using EJB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Record Locking using EJB" Watch "Record Locking using EJB" New topic
Author

Record Locking using EJB

L Goundalkar
Ranch Hand

Joined: Jul 05, 2001
Posts: 395
Hi,
Can anyone please explain me how to achieve Oracle Row level record locking using Enterprise Java Bean ?
Thanks for the time.


<b>L G Goundalkar</b><br /> <a href="mailto:lggoundalkar@yahoo.com" rel="nofollow">lggoundalkar@yahoo.com</a> <br />Sun Certified Programmer for Java 2 Platform.<br />Sun Certified Web Component Developer for J2EE.
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3879
It depends entirely upon the container you are using. Tell us which EJB container vendor you mean, and (after moving this to the appropriate forum) we can probably help you.
Kyle


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
L Goundalkar
Ranch Hand

Joined: Jul 05, 2001
Posts: 395
Hi Kyle,
Since EJB specificaiton is standard one and the J2EE servers which support the J2EE has to abide by the specification, do we need to consider the container when designing for Record Lock feature in the application which we are building..?
Let us say if we use Websphere or Weblogic, what has to be done if we want to implement row level record locking in the application ?
If record lock depends on the container then doesn't it contradict the idea of J2EE certified App servers ?
Thanks for the time.
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
Record locking depends on isolation levels and this is not covered by the EJB Specification (see Section 17.3.2). Most Application Servers do definitely address this, however they do it in a vendor-specific way.
If record lock depends on the container then doesn't it contradict the idea of J2EE certified App servers?
Not really. Record locking depends highly on things outside of the EJB Container's control such as the capabilities of the target database. Therefore, it would be impossible to require adherence to an absolute behavior without crippling performance (all locking would have to be handled in the EJB Container instead of delegating to the database). Besides, the point of the specification is not binary portability. It is to make portability between J2EE Servers possible without significant rewriting of the application. I think it is achieved in this regard.
L Goundalkar
Ranch Hand

Joined: Jul 05, 2001
Posts: 395
Thats fine.
Can you please guide me how to go about implementing record locking using EJB ? Take any applicaiton server as example.
Cheers.
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
I am most familiar with WebLogic so I will use that as my example...
To control record-locking in WebLogic you must set the isolation level on your EJB in a vendor-specific descriptor. In the weblogic-ejb-jar.xml there is an element called transaction-isolation which contains an element called isolation-level with the following possible values: TransactionSerializable | TransactionReadCommitted | TransactionReadUncommitted | TransactionRepeatableRead | TransactionReadCommittedForUpdate | TransactionReadCommittedForUpdateNoWait. It is important to note that not all databases support every isolation level... so you once again need to spend a bit of time investigating which ones are available for your particular database.
If you have questions on how to set isolation levels for a particular J2EE Server then I suggest you post the question to the specific forum for that Server. In general, setting isolation levels is a pretty simple task that can have huge consequences on the performance and behavior of your application so be careful.
L Goundalkar
Ranch Hand

Joined: Jul 05, 2001
Posts: 395
Hi,
I went through the link for Isolation Level in BEA site. Well it just helps us to define the degree to which a transaction exposes updated but uncommitted data to other transactions.
If you consider the requirement I have which is locking a record so that no other user is allowed to update the same. If the other user tries to update the record he should get notification that someone else has already obtained the lock. This can be achieved through simple Java Bean which holds lock status for the records.
Is this possible by using just Entity bean where I query for the record using "Select * from <mytable> where <criteria> for Update Nowait". Or do I need to use some combination of Session and Entity bean to achieve this?
Hope I made the requirements clear.
Cheers.
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
If you consider the requirement I have which is locking a record so that no other user is allowed to update the same. If the other user tries to update the record he should get notification that someone else has already obtained the lock. This can be achieved through simple Java Bean which holds lock status for the records.
We are both talking about the same thing. The above example discusses how to enforce concurrency on a transactional basis... which is often what we want. To this on a per-bean basis you would need to use the use-select-for-update in the weblogic-cmp-jar.xml descriptor for your CMP Bean.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Record Locking using EJB
 
Similar Threads
Locking the record using the cookie
Request For Comments
Logical/File Locking and nested synchronisation
Is it ok to NOT taking care of client crash?
Runing two alone mode applications?