7 Replies Latest reply on Mar 5, 2008 10:21 PM by www.supernovasoftware.com

    Unpredictable persistence problems -- please help

    www.supernovasoftware.com

      I am using Seam 2.0.1 on JBAS 4.2.2 with PostgreSQL 8.2.6 and jrockit.


      I have been having quite a few problems with some code that imports data from some tables into a new format for version 2 of my inventory system.


      In order to import and transform the data I fill in my objects with old data and then run all of the steps that would have occurred to get the data where it should be.  Both sets of data are in the same PostgreSQL database and all entities are in the same ear.


      For example to get inventory into table of the new inventory system.  I need to get the data from the old objects and fill in the new object and feed it to my SLSB.  All code is handled  through SLSB that use



          @PersistenceContext
          public EntityManager entityManager;



      I have never seen these operations fail under normal use of the application.  However, when I try to string them together in a sequence to replicate several operations needed for the import I get random results.


      It will be working and process the import of multiple records only to stop working and skip some of the steps.
      Some of the steps are persisted, but others are not.  I just want all operations to be handled in the same transaction and complete whether the user calls them one at a time or I do the following:



           @Override
           public void addShippedOrder(RecordDOS recordDOS) {
                if(recordDOS.getNumJtsSent()!=null && recordDOS.getNumJtsSent()>1)
                   {
                       log.info(++i +" Open Shipment: "+ recordDOS.getPoNum());
                       PoPipe poPipe = createPoPipeFromRecrodDOS(recordDOS);
                       shipmentDAO.flush();
                       Shipment shipment = shipmentDAO.getNewInstance();
                                shipment = (Shipment) stateDAO.setProperitesByState(shipment, poPipe, false);
                                shipment.setOrderComplete(true);
                                shipment.setParentState(poPipe);     
                                shipment.setPoPipe(poPipe);
                                shipment.setVoyage(voyageDAO.findActiveVoyageByVesselName(recordDOS.getVessel()));
                                shipment.setAmountSent(recordDOS.getNumFtSent());
                                shipment.setNumPieces(recordDOS.getNumJtsSent());
                                shipment.setNumBundles(recordDOS.getNumBundles());
                                shipment.setUnitsSent(unitDAO.findById(Constants.UNITS_FT_ID));
                                shipmentDAO.action(shipment);
                                shipmentDAO.flush();
                       recordDOS.setPoPipe(poPipe);
                   }
           }     



      All code shown below is either an entity or SLSB and only calls other SLSB or entity.


      I tried calling flush all over the place.  I tried requiring a new transaction.


      This is causing me major problems and I would greatly appreciate any help on narrowing this down.


      Sometimes this works and sometimes it does not.  I do not know the cause.  If it is working it will import a hundered or more records, but I can come back 5 minutes later and try another one only to have it bring in half of the steps and leave me with corrupted difficult to repair data.


      Problems are the same on different machines on Windows and Linux.