4 Replies Latest reply on Apr 3, 2009 12:19 AM by gonorrhea

    Enrity dirty checking in flushMode=MANUAL

    goik

      I do have an Entity User and a corresponding UserHome with manual flushing enabled:



      @Name("userHome")
      @Scope(ScopeType.CONVERSATION)
      public class UserHome extends EntityHome<User> {
          ...
        @In(create=true ) private EntityInfoManager entityInfoManager;
        private String pw1, pw2;
          ...
        @Override
        public String update() {
          final User u = getInstance();
          ...
          if (someCondition) {
            return null;
          } else {
            u.setUserPassword(PasswordUtil.generateRandomSaltMd5Digest(pw1));
          } 
          getEntityManager().flush();
          return super.update();
        }
        @Override 
        @Begin(flushMode=FlushModeType.MANUAL, join=true)
        public void create() {
          super.create();
          //business logic code omitted
        }
      }



      The corresponding view user.xhtml contains:



      <h:commandButton id="update" value="Update" action="#{userHome.update}"
      rendered="#{userHome.managed}" />



      The User entity references other entities that may or may not be changed in the conversation and so far it works.


      Now I want to display this update button shaded as long as no entity has been changed. In other words: I want to know if the User instance object or any referenced object within the conversation is in a dirty state.


      I searched the Seam documentation and this (plus the former) Seam user's forum but did not find any hint.

        • 1. Re: Enrity dirty checking in flushMode=MANUAL
          stephen

          Haven't tried, but falling back to the hibernate session should work:


          ((Session)entityManager.getDelegate()).isDirty()

          • 2. Re: Enrity dirty checking in flushMode=MANUAL
            goik

            This works for me, thanks!

            • 3. Re: Enrity dirty checking in flushMode=MANUAL

              This is very close to the answer I am looking for as well, except for one thing. I want to know if a specific entity is dirty. I've got several different entities managed by the same entityManager and I have a need to know if one of the entities is dirty (in order to put up a confirmation dialog when the user attempts to navigate to a different entity).


              Any ideas?


              Thanks,
              Jeremy

              • 4. Re: Enrity dirty checking in flushMode=MANUAL
                gonorrhea

                have you looked on the Hibernate forum?  I just scanned the Hibernate Session API here:


                My Link


                and didn't see any methods that would be applicable.


                good question...


                maybe this would work:


                If you know which entity you're interested in checking then do this:


                EquipmentRepair equipmentRepair = entityManager.find(EquipmentRepair.class, repairId);



                then compare all the properties of the entity's class with the values of the potentially dirty copy of the entity in the SMPC for the injected EntityManager.  I'm not sure how to get the instance of an entity that is currently being managed by the EntityManager in SMPC.  Is there an API for this in JPA or Hibernate???


                This would basically require access to entities in the first-level cache...