4 Replies Latest reply on Jul 26, 2005 8:21 PM by V S

    Optimistic version field does not increment with cmp2.x jdbc

    Johan Borchers Newbie


      I'm using JBoss 3.2.6, JDK build 1.4.2_05-b04 and MySQL 4.0.20.

      I tried the new cmp2.x jdbc2 pm container with an optimistic lock version field. But I don't really understand what should happen with the version field.
      Listing 1 is the version field which is incremented when the description field changes.
      I expect the same sort behaviour with cmp2.x jdbc2 pm.
      But in listing 2 you can see that the version field is not incremented at all but the description field is updated (and also the other fields!).

      Do I have to do some work by myself to upgrade the version field for the cmp2.x jdbc2 pm container?
      Normally I would think that if thread A is taking a long time in updating and thread B is fast and updates the version field thread A will try to update a record with and old version number and than an exception should appear because no row is updated.

      Can somebody tell me the normal behaviour of the cmp2.x jdbc2 pm container and using a version field?



      Listing 1 of update of description field with the standard CMP 2.x container :

      2004-11-07 22:10:03,968 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreEntityCommand.Archive] Executing SQL: UPDATE t_archive SET arc_version=?, arc_description=? WHERE arc_seq=? AND arc_version=?
      2004-11-07 22:10:03,968 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCLongVersionFieldBridge.Archive#version] param: i=1, type=BIGINT, value=16
      2004-11-07 22:10:03,968 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMP2xFieldBridge.Archive#description] param: i=2, type=VARCHAR, value=Nog een keer
      2004-11-07 22:10:03,968 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCCMP2xFieldBridge.Archive#key] param: i=3, type=INTEGER, value=31
      2004-11-07 22:10:03,968 TRACE [org.jboss.ejb.plugins.cmp.jdbc.bridge.JDBCLongVersionFieldBridge.Archive#version] param: i=4, type=BIGINT, value=15

      Listing 2 of update of description field with the cmp2.x jdbc2 pm CMP container:

      2004-11-07 22:27:05,906 DEBUG [org.jboss.ejb.plugins.cmp.jdbc2.schema.EntityTable.t_archive] executing : update t_archive set arc_version=?, arc_default=?, arc_code=?, arc_description=? where arc_seq=? and arc_version=?
      2004-11-07 22:27:05,906 TRACE [org.jboss.ejb.plugins.cmp.jdbc2.bridge.JDBCCMPFieldBridge2.Archive#version] param: i=1, type=BIGINT, value=16
      2004-11-07 22:27:05,906 TRACE [org.jboss.ejb.plugins.cmp.jdbc2.bridge.JDBCCMPFieldBridge2.Archive#default] param: i=2, type=TINYINT, value=true
      2004-11-07 22:27:05,906 TRACE [org.jboss.ejb.plugins.cmp.jdbc2.bridge.JDBCCMPFieldBridge2.Archive#code] param: i=3, type=VARCHAR, value=A3
      2004-11-07 22:27:05,906 TRACE [org.jboss.ejb.plugins.cmp.jdbc2.bridge.JDBCCMPFieldBridge2.Archive#description] param: i=4, type=VARCHAR, value=Nog maar een keer
      2004-11-07 22:27:05,906 TRACE [org.jboss.ejb.plugins.cmp.jdbc2.bridge.JDBCCMPFieldBridge2.Archive#key] param: i=5, type=INTEGER, value=31
      2004-11-07 22:27:05,906 TRACE [org.jboss.ejb.plugins.cmp.jdbc2.bridge.JDBCCMPFieldBridge2.Archive#version] param: i=6, type=BIGINT, value=16
      2004-11-07 22:27:05,906 TRACE [org.jboss.ejb.plugins.cmp.jdbc2.schema.EntityTable.t_archive] updated rows: 1