2 Replies Latest reply on Aug 13, 2010 1:51 PM by lvdberg

    problems with objects synchronization

    lrpieri

      Hi,


      I have one object(A) that has a list of objects(B), for each element of 2nd list there are one list of objects(C) and for each c element there are one single object(D).


      Abstracting the way how it is showed on the view, what I whant is remove de D element.


      The relevant code is follow



      <s:div id="divDevices">
           <rich:dataGrid styleClass="center" value="#{_producerProvider.deviceProducerProviders}" var="_deviceProducerProvider" columns="5" style="margin-top:10px;">
           <h:panelGrid columns="2">
                <a4j:commandLink action="#{companyHome.removeDeviceFromDeviceProvider(_deviceProducerProvider)}" 
                     reRender="divDevices"
                     rendered="#{empty _deviceProducerProvider.fileApplications}">
                     <h:graphicImage value="/resources/img/cancel-12x12.png"/>
                </a4j:commandLink>
           <h:graphicImage value="/resources/img/add.png" rendered="#{not empty _deviceProducerProvider.fileApplications}"/>
           <h:outputLabel value="#{_deviceProducerProvider.device.serialNumber}"/>
           </h:panelGrid>
           </rich:dataGrid>
      </s:div>





      @Name("companyHome")
      public class CompanyHome extends EntityHomeValidation<Company> {
      ...
           public void removeDeviceFromDeviceProvider(DeviceProducerProvider deviceProducerProvider){
                entityManager.remove(deviceProducerProvider);
                entityManager.flush();
      //          log.debug("deviceProducerProvider: " + deviceProducerProvider);
      //          int index = getInstance().getProviders().indexOf(deviceProducerProvider.getProducerProvider());
      //          log.debug("Index: " + index);
      //          ProducerProvider producerProvider = getInstance().getProviders().get(index);
      //          producerProvider.getDeviceProducerProviders().remove(deviceProducerProvider);
      //          new GenericDAO().update(producerProvider);
      //          this.update();
           } 
      ...
      }



      I'm having two situations for method removeDeviceFromDeviceProvider:
      1st: the non commented code remove the object just from the DB but not from the managed object.


      2nd: the commented code do the oposite. Remove from the managed object but not from DB.


      I think I should not do the both things or I will not be using the resources of the framework and will start having synchronizing problems.


      Does anybody have any idea what should I do?


      Thanks for all and sorry for my bad english.

        • 1. Re: problems with objects synchronization
          lrpieri

          Hello folks!


          Any idea?


          Thanks!

          • 2. Re: problems with objects synchronization
            lvdberg

            Hi,


            send in some more code and we can give better help. What I suspects is that somethings' wrong with your entity mapping. If you configure the entity and its relations correctly, removing an objcet from the object tree will lead to deleting and updating anywhere its is needed (as long as your domain model permits that). Otherwise you have to walk through the object tree and remove all the relations yourseld prior to deleting.


            But anyway, send some more code and we can give you some help.


            Leo