0 Replies Latest reply on Aug 5, 2003 1:58 PM by tom.purvis

    <row-locking> question

    tom.purvis

      I'm writing an app that uses CMP to manage all entity beans' persistance. I'd like to use a pessimistic concurrency approach, where a user will be blocked from opening an entity if some other user already has it open. So I'd like to have the request to findByPrimaryKey throw an exception if somebody else has that record "open".

      I'm using a Stateless Session bean to operate on the Entity Bean. A Servlet instantiates the Session bean, then provides the ID of the record it wants to open. The session bean calls findByPrimaryKey using the ID.

      Once I've used the bean to populate a Form on the client's returned page, I put a reference to the bean's Local Interface into the HttpSession obj. This would keep a reference to it in the client thread, and (I had hoped) would effectively lock the row so that other attempts to pull up the entity would fail.

      So I opened a record for editing, then logged a second user on and had that user attempt to open the same record. Both users could open the same record, and stomp on each others' changes.

      After the exception was never thrown, and my second (test) user could open the same record, I found a key in standardjbosscmp-jdbc.xml and standardjaws.xml called <row-locking>. I set it from False to True and bounced JBoss. No diff.

      So the questions:

      1. Am I even on the right track expecting this to work? Is there a better J2EE/JBoss approach to avoiding this concurrency problem?

      2. Is it possible that this is failing because I'm using MySQL as my datasource? I'm using version 4.0.13 of MySQL with InnoDB, and I'm using InnoDB AFAIK. In other words, if everything else was right, would this approach work?