2 Replies Latest reply on May 2, 2006 12:41 PM by gavin.king

    updating the view with em.refresh()

    kh2ouija

      I have a domain model like this: Company -* Department -* Employee

      On a Company's page I list all Departments with their Employees. The code on the page (facelets) just iterates and displays the Departments and their Employees.

      When I add or delete an Employee, the page has to be updated so I do this in the backing bean:

      em.refresh(company);
      departments = company.getDepartments();


      This works ok when adding an Employee. But when I refresh the company after *deleting* an employee I get this:

      javax.ejb.EJBTransactionRolledbackException: javax.persistence.EntityNotFoundException: org.hibernat
      e.UnresolvableObjectException: No row with the given identifier exists: [com.example.Employee#231]
      


      Any idea why, or how to avoid this? Or maybe a different way of refreshing my view? Thanks.


      P.S.

      I also tried like this instead of refreshing the company:

      departments = departmentDAO.getAll(); // straightforward em query call



      No error now, but the the view isn't updated correctly after either adding or deleting an Employee (new Employees don't show up immediately, deleted ones still show).

      Any help would be highly appreciated. Thanks.


        • 1. Re: updating the view with em.refresh()
          andy.2003

          Hi as far as I know the em.refresh(Entity) method is to refresh an existing Entity. I use it to load lazy data of entities stored in the session. I store the User-Entity in the session and to get the roles of the user i have to call:

          em.refresh(lUser);
          lUser.getRoles();


          If you delete an Entity, you should call the em.find() method (I'm not quite shure, if it is the best way)

          I'm also intrested in a best practice.

          - Andreas

          • 2. Re: updating the view with em.refresh()
            gavin.king

            This kind of discussion should be moved to the Hibernate or JBoss EJB3 forums, its not Seam specific.