3 Replies Latest reply on Sep 19, 2006 10:49 AM by odg

    Problem with updating same row several times in one transact

    wonker

      I am a relative newbie to JBoss so excuse my dumbness or the lack of technical info, but heres my best shot. I am using ejbs (generated via xdoclet) and JBoss 3.2.5.

      In my facade methods, I can potentially update the same db row several times in one transaction i.e.

      for(Iterator it = updates.iterator()l; it.hasNext();) {
      
       // Get value object
       TestValue value = (TestValue) it.next();
      
       // Get local home instance
       TestLocalHome home = (TestLocalHome) homeFactory.getLocalHome(TEST_LOCAL_HOME);
      
       // Get local instance
       TestLocal local = home.findByPrimaryKey(value.getId());
      
       // Update local instance
       local.setCommissionFeeValue(value);
      
       // Print some debug
       System.err.println("Updating - " + local.getCommissionFeeValue());
      }
      


      In sql terms it would be like -

      UPDATE TEST SET VALUE = 'A' WHERE ID = 1;
      UPDATE TEST SET VALUE = 'B' WHERE ID = 1;
      UPDATE TEST SET VALUE = 'C' WHERE ID = 1;
      UPDATE TEST SET VALUE = 'D' WHERE ID = 1;
      ...
      


      Although for some reason, JBoss only issues an UPDATE sql command to the db, only after the last update (I know this through the logs as only then does the EJBQL command get dumped to the logs).

      The reason this is a problem, is that I have a trigger on the table which after these updates writes into an audit table, recording all chanes to the row. So for the scernaio above I should see 4 audit rows, but I only see the 1 (corresponds to the last update).

      Does anyone have ideas about if this is a coding issue or if JBoss is trying to be clever. Is there a way I can make it un-clever :)

      Cheers,

      Niraj