4 Replies Latest reply on Nov 16, 2001 4:21 AM by apo

    Update in field being part of PK - problem

    apo

      Hi all you sinners and mortals !
      Is there any immortal out there ? If yes, then he/she will be able to help me :
      Let's assume we have a CMP Entity bean

      public class EntityBean1 {
      public Long id;
      public String f1 ;
      public long f2 ;

      public void incrementF2() {
      f2++;
      }

      }

      ID is the primary key and fields f1 and f2
      belong to unique key constraint. In other words there's a unique key constraint defined in database table:
      alter table EntityBean1 add constraint EB_UQ
      unique ( f1, f2 )
      There's a row in the above table with values :
      id = 1;
      f1 = 'sth';
      f2 = 0;

      In my facade stateless session bean (CMT) I have a method with transaction attribute set to "Required" doing this:
      1 finding the bean with id = 1
      2 calling its incrementF2() method (it's a business method exposed in remote interface )
      3 creating new EntityBean1 with id = 2 (new id ) and f1 = 'sth' (the same) and f2 = 0 (old value) - and here I get an SQLException telling me that unique key constraint EB_UQ had been violated.
      All that is done within one transaction. Transaction attribute of incrementF2() method is set to "Required" as well.
      Obviously JBoss tries to create new Entity bean before updating the old one in DB.
      Have you ever met such an issue ? Do you know any workaround / solution ?
      I'd appreciate any help
      Andrzej

        • 1. Re: Update in field being part of PK - problem
          apo

          The field f2 mentioned in the topic subject is not part of Primary Key . Sorry for confusion.

          • 2. Re: Update in field being part of PK - problem
            danch1

            Recent versions of JBoss have been modified to call store before any create or finder methods are actually executed. This for sure _will_ be in version 2.4.4 when it's released, but I can't remember if it's in 2.4.3.

            In the meantime, either grab JBoss 2.4 branch from CVS and build, or well, in this case a workaround is not real easy to come by - if you mark 'incrementF2()' RequiresNew, you'll probably deadlock, I suppose you could use bean managed transactions, but that's not necessarily trivial...

            • 3. Re: Update in field being part of PK - problem
              apo

              This isn't in 2.4.3 cause I'm using JBoss 2.4.3 and the problem exists.
              Thanks anyway

              • 4. Re: Update in field being part of PK - problem
                apo

                Hi danch1
                I've just checked out JBoss 2.4.8 from CVS , built it successfully and my problem still exists.
                Are you still sure that something has been done and it will appear in 2.4.4 ?