3 Replies Latest reply on Feb 4, 2005 8:22 AM by Terry Paterson

    Optimistic Locking using Modified Strategy JBoss 3.2.3

    Jerrold Eads Newbie

      I am using 3.2.3 and I am configuring optimistic locking in the following manner:

      jboss.xml

      
      <entity>
       <ejb-name>MSSQLServer2000Sequencher_01REF_Users</ejb-name>
       <local-jndi-name>MSSQLServer2000Sequencher_01REF_Users</local-jndi-name>
       <configuration-name>Non-nullable foreignKey ejbPostCreate and Optimistic Container</configuration-name>
      <entity>
      
      <container-configurations>
      <!-- <Extends Per Transaction for the purpose of inserting record after post create> -->
       <container-configuration extends="Instance Per Transaction CMP 2.x EntityBean">
       <container-name>Non-nullable foreignKey ejbPostCreate Container</container-name>
       <insert-after-ejb-post-create>true</insert-after-ejb-post-create>
       </container-configuration>
      
      <!-- <Extends Per Transaction for the purpose of Optimistic Locking and inserting record after post create> -->
       <container-configuration extends="Instance Per Transaction CMP 2.x EntityBean">
       <container-name>Non-nullable foreignKey ejbPostCreate and Optimistic Container</container-name>
       <insert-after-ejb-post-create>true</insert-after-ejb-post-create>
       <!-- <overrides: org.jboss.ejb.plugins.lock.noLock> -->
       <locking-policy>org.jboss.ejb.plugins.lock.JDBCOptimisticLock</locking-policy>
       </container-configuration>
      
      <!-- <Extends Per Transaction for the purpose of Optimistic Locking JE 8/18/2003> -->
       <container-configuration extends="Instance Per Transaction CMP 2.x EntityBean">
       <container-name>Optimistic Container</container-name>
       <!-- <overrides: org.jboss.ejb.plugins.lock.noLock> -->
       <locking-policy>org.jboss.ejb.plugins.lock.JDBCOptimisticLock</locking-policy>
       </container-configuration>
      </container-configurations>






      jbosscmp-jdbc.xml


      <defaults>
       <datasource>java:/MSSQLServer2000Sequencher_01REF</datasource>
       <datasource-mapping>MS SQLSERVER2000</datasource-mapping>
       <pk-constraint>true</pk-constraint>
       <fk-constraint>false</fk-constraint>
       <preferred-relation-mapping>foreign-key</preferred-relation-mapping>
       <read-ahead>
       <strategy>on-load</strategy>
       <page-size>1000</page-size>
       <eager-load-group>*</eager-load-group>
       </read-ahead>
       <list-cache-max>1000</list-cache-max>
      </defaults>
      <enterprise-beans>
       <entity>
       <ejb-name>MSSQLServer2000Sequencher_01REF_Users</ejb-name>
       <create-table>false</create-table>
       <remove-table>false</remove-table>
       <table-name>Users</table-name>
       <cmp-field>
       <field-name>user</field-name>
       <column-name>UserID</column-name>
       </cmp-field>
       <cmp-field>
       <field-name>employeeId</field-name>
       <column-name>EmployeeID</column-name>
       </cmp-field>
       <cmp-field>
       <field-name>firstName</field-name>
       <column-name>FirstName</column-name>
       </cmp-field>
       <cmp-field>
       <field-name>lastName</field-name>
       <column-name>LastName</column-name>
       </cmp-field>
       <cmp-field>
       <field-name>initials</field-name>
       <column-name>Initials</column-name>
       </cmp-field>
       <cmp-field>
       <field-name>eMail</field-name>
       <column-name>EMail</column-name>
       </cmp-field>
       <cmp-field>
       <field-name>locked</field-name>
       <column-name>Locked</column-name>
       </cmp-field>
       <cmp-field>
       <field-name>active</field-name>
       <column-name>Active</column-name>
       </cmp-field>
       <cmp-field>
       <field-name>changePasswordOnNextLogin</field-name>
       <column-name>ChangePasswordOnNextLogin</column-name>
       </cmp-field>
       <cmp-field>
       <field-name>dateCreated</field-name>
       <column-name>DateCreated</column-name>
       </cmp-field>
       <cmp-field>
       <field-name>createdBy</field-name>
       <column-name>CreatedBy</column-name>
       </cmp-field>
       <cmp-field>
       <field-name>dateModified</field-name>
       <column-name>DateModified</column-name>
       </cmp-field>
       <cmp-field>
       <field-name>modifiedBy</field-name>
       <column-name>ModifiedBy</column-name>
       </cmp-field>
       <optimistic-locking>
       <modified-strategy/>
       </optimistic-locking>
       </entity>
      </enterprise-beans>
      


      When two users open the same users record and do updates on different fields they wind up with a lost update. The first update is lost and the second update does not throw an exception as it should with the modified strategy. What have I setup wrong? Is it true that after 3.2.2 that org.jboss.ejb.plugins.lock.JDBCOptimisticLock is deprecated? If so how should the container configuration look?

      Thanks
      Jerry