2 Replies Latest reply on Dec 2, 2007 9:31 AM by pmuir

    observing database updates

    robshep

      I'd like to observe the changes being made to persisted entities.

      I'm currently using an EntityHome instance for entity management and have something like this.

      @Override
      public String update()
      {
       MyObj old = (MyObj)this.getEntityManager().find(MyObj.class, this.getInstance().getId());
       MyObj incoming = this.getInstance();
       System.out.println("OLD: " + old.getDescription() + ", NEW: " + incoming.getDescription() );
       return super.update();
       }
      


      I've seen however, that even though the entity instance isn't persisted through to the underlying DB yet, the entitymanager is being clever and finding the instance coming in from the JSF components.

      To enable me to see the differences between the a) the data actually in the DB and b) the data currently known to the entitymanager.....

      I think I need to get hold of a new fresh entitymanager instance, one which doesn't have a cache of anything related.

      Please could somebody explain how I may get such an instance. OR, if you have any better places in mind for where I can observe this data flow.

      many thanks and kindest regards

      Rob

        • 1. Re: observing database updates
          andygibson

          You could try creating a new entity manager from the entity manager factory, and try loading objects using that manager to get the database objects.

          I think you can do it as :

           @In
           private EntityManagerFactory entityManagerFactory;
          


          I believe the entityManagerFactory is created as an application scoped seam component.

          To create a new entityManager you can call createEntityManager() on the factory object.

          Cheers,

          Andy




          • 2. Re: observing database updates
            pmuir

            Alternatively define a second SMPC in components.xml from the same jndi lookup for the Persistence Unit factory.