2 Replies Latest reply on Mar 30, 2004 2:54 AM by Joachim Van der Auwera

    Instance not automatically updated in 3.2.4RC2 ?

    Joachim Van der Auwera Expert

      I have the following piece of code in my test suite :

       public void testBoxSale()
       throws Exception
       {
       // create the necessaty stuff
       BatchSelectorEJB batchSelector = batchSelectorHome.create();
       WeightEJB box = weightHome.create( WeightConstants.TYPE_ArticleWeight, "01" );
       box.setPackagingType( WeightConstants.PACKAGING_TYPE_BOX );
       WeightEJB piece1 = weightHome.create( WeightConstants.TYPE_ArticleWeight, "01" );
       piece1.setPackagingGroup( box );
       WeightEJB piece2 = weightHome.create( WeightConstants.TYPE_ArticleWeight, "01" );
       piece2.setPackagingGroup( box );
       WeightGroupEJB sale = weightGroupHome.create( "R" + System.currentTimeMillis() );
      
       // sell piece1 and check that the piece is no longer part of the box
       assertNotNull( piece1.getPackagingGroup() );
       piece1.setSale( sale );
       assertNull( piece1.getPackagingGroup() );
       // the other piece and the box are not yet sold
       assertNull( box.getSale() );
       assertNull( piece2.getSale() );
       assertEquals( box.getUOID(), piece2.getPackagingGroup().getUOID() );
      
       // sell the box and check that piece2 is also sold
       box.setSale( sale );
       assertEquals( sale.getUOID(), box.getSale().getUOID() );
       // @todo following line was not necessary before, but it is in JBoss 3.2.4RC2
       piece2 = weightHome.create( piece2.getUOID() );
       assertNotNull( piece2.getSale() );
       assertEquals( sale.getUOID(), piece2.getSale().getUOID() );
      
       // cleanup
       piece1.remove();
       piece2.remove();
       box.remove();
       sale.remove();
       batchSelector.remove();
       }
      



      The important piece is in bold.
      the sale, piece1 and piece2 objects are session facades for entity beans. Before, calling box.setSale has its sideeffects immediately visible in the piece2 SFSB, but this is no longer true, I now have to recreate the session facade for the changes to be visible.

      What could be causing this or how can I fix it?

      Joachim

      W

        • 1. Re: Instance not automatically updated in 3.2.4RC2 ?
          Alexey Loubyansky Master

          What is done in box.setSale( sale ); and piece2 = weightHome.create( piece2.getUOID() );?

          • 2. Re: Instance not automatically updated in 3.2.4RC2 ?
            Joachim Van der Auwera Expert

            Alex,

            The create method looks liks this

             public void ejbCreate( UOID uoid )
             throws CreateException
             {
             setUp( );
             try
             {
             log.trace( "create Weight entity ejbCreate(" + uoid + ")" );
             DMWeightEJBLocal entity = entityHome.findByPrimaryKey( uoid );
            
             this.uoid = uoid;
             setMediator( entity );
             }
             catch ( FinderException e )
             {
             throw new CreateException( "Weight: UOID " + uoid.getId( ) + "not found" );
             }
             }
            


            It basically just makes sure the entity is available for the other methods. It then creates a mediator object to handle the getters and setters (this code is generated by Uni-d, an OSS project which (amongst other things) allows the creation of beans with inheritance). The mediator handles the inheritance dependencies.

            The setSale is rather complex, but in short, it a certain condition is met, a finder on the entity beans is called and the state in these entity beans is modified. It is that change which is not visible.

            I assume I could fix this by not caching the entity object, but by doing findByPrimaryKey each time I need it. However, this seems to be a very inefficient way to do things.

            Joachim