3 Replies Latest reply on Apr 7, 2004 4:20 PM by amoro99

    Optimistic Locking fails when field is null

    Jerrold Eads Newbie

      I am using optimistic locking with the modified strategy. When I try to update a field that contains a null value I get the following error:

      2003-08-18 14:13:28,703 ERROR [org.jboss.ejb.plugins.LogInterceptor] TransactionRolledbackException, causedBy:
      javax.ejb.EJBException: Update failed. Expected one affected row: rowsAffected=0id=Primary key: 731

      If I try to update the same field when it does not contain a null value the update works fine. I can set the field to another non-null value or to null with no problems.

      Jboss.xml:


      <ejb-name>Project</ejb-name>
      <local-jndi-name>Project</local-jndi-name>
      <configuration-name>Optimistic Container</configuration-name>


      ...

      <container-configurations>
      <!-- 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:

      <jbosscmp-jdbc>

      <!--datasource>java:/DefaultDS
      <datasource-mapping>Hypersonic SQL</datasource-mapping>
      <create-table>true</create-table>
      <remove-table>true</remove-table>
      <pk-constraint>true</pk-constraint>
      <preferred-relation-mapping>foreign-key</preferred-relation-mapping-->


      <enterprise-beans>

      <ejb-name>Project</ejb-name>
      <table-name>Project</table-name>
      <ejb.invalidateFinderCollectionAtCommit>false</ejb.invalidateFinderCollectionAtCommit>
      <ejb.maxBeansInCache>1000</ejb.maxBeansInCache>
      <ejb.cacheCreate>true</ejb.cacheCreate>
      <ejb.maxBeansInPool>1000</ejb.maxBeansInPool>
      <ejb.transactionCommitMode>Shared</ejb.transactionCommitMode>
      <cmp-field>
      <field-name>id</field-name>
      <column-name>ID</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>priority</field-name>
      <column-name>Priority</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>status</field-name>
      <column-name>Status</column-name>
      </cmp-field>
      <cmp-field>
      <field-name>assignedTo</field-name>
      <column-name>AssignedTo</column-name>
      </cmp-field>

      <optimistic-locking>
      <modified-strategy/>
      </optimistic-locking>


      Has anyone else run into this problem? Any help will be greatly appreciated.

      Thanks
      Jerry