6 Replies Latest reply on Feb 1, 2011 2:27 PM by serkan.s.eskici.online.nl

    EntityHome Reset

    kabil

      Hi;


      I'm confused about EntityHome behaviour. Because default flush mode is auto, any changes made to instance of EntityHome is flush as being dirty.


      So I need to make EntityHome brand-new, with no loaded instance. Also I want to rollback the changes made to the Entity instance, what methods must be called to accomplish this without entitymanager to flush changes made?


      Thanks  in advance

        • 1. Re: EntityHome Reset
          mwohlf

          same confusion here, what I did was this




          • to prevent early flushes from the EntityHome I use flush-mode=manual when I start the conversation





          • to reset EntityHome I use clearInstance() and additional remove the instance from the conversation scope with Contexts.getConversationContext().remove(changeRequestError)




          but I am not sure if this is the seam way, manually removing stuff from the conversation context seems a bit hack-ish, in the example apps I have also seen some kind of HolderObject to host an instance during a conversation, if anyone got a better solution to these common problems I would like to know...

          • 2. Re: EntityHome Reset
            kabil

            Well,
            In fact I am making new seam-gen templates for gui and back end, I use modal panels for edit, delete new entity creation, it is almost done but I am troubled with this being dirty if any changes is made.


            I also used manual mode and clearinstance(), but it also sets dirty of course, so clearDirty must be called.


            Why I did not want to use manual mode is because after I add a new Entity object when I rerender my datatable (with onComlete event), I could not see the one created newly, but if I reRender manually after whole create object operation, datatable is refreshed with the new one. So to make this work I needed to call seam-gen'ed XXXList component's refresh() method. In fact which must be automatically called while reRendering. This one was another story..


            I didnt know Contexts.getConversationContext().remove(changeRequestError) be called. It seems really hacking in an unusual way.

            • 3. Re: EntityHome Reset
              mwohlf

              well err... just to be clear changeRequestError is the name of my entity that I want to remove from the conversation scope, I just copied this from my source, I am not really proud of this line of code I admit and still looking for a better way to do this...

              • 4. Re: EntityHome Reset
                hakanm

                did you have chance to resolve this problem 'cause we are facing with this too.
                thanks in advance.

                • 5. Re: EntityHome Reset
                  vata2999

                  Hi,
                  If u r using EntityHome and i understand your problem correctly
                  maybe this helps you


                  define your Entity in component.xml as Seam Component



                  <component class="com.mydomain.myproject.model.User" name="user" />



                  there is a getNewInstance method you can ovveride as below




                  ValueExpression<User> u;
                  
                  @Override
                  public ValueExpression getNewInstance() {
                   u = Expressions.instance().createValueExpression("#{user}", User.class);
                   return u;
                  }
                  


                  then u can access newInstance of your object



                  User u = (User) getNewInstance().getValue();






                   

                  • 6. Re: EntityHome Reset
                    serkan.s.eskici.online.nl

                    Use entityManager.refresh(yourEntity) to reload the state from the db.


                    This is what the EntityManager API says about this method:




                    refresh(Object entity):
                              Refresh the state of the instance from the database, overwriting changes made to the entity, if any.


                    What you also can do is call setId(null) in EntityHome, to make sure that you don't make any changes to an existing entity.