2 Replies Latest reply on Apr 27, 2006 6:22 PM by Gavin King

    Invoke alway the factory

    Udo Krass Newbie


      i have a little problem.
      I store an entity existingUser in my session-Context when a request page is called with the username as request parameter.

      public class UserBoxAction implements UserBox {
       private static final Logger log = Logger.getLogger(UserBoxAction.class);
       private User existingUser;
       private transient Context sessionContext;
       private String username;
       private EntityManager em;
       public void listUserDetails() {
       //if the user comes from the guestbook back and does not start a request
       if (username.equals("")||username==null)
       username = existingUser.getUsername();
       log.info("existingUser will be injected" + username);
       existingUser = (User) em.createQuery(
       "from User where username=:username").setParameter("username",
       //set the selected User in the Session, because nothing else will work
       // properly
       sessionContext.set("existingUser", existingUser);

      But when i call this page twice in the same session with another username, the factory isn't working. That's right, because the existingUser entity is known in the context now. But that's not what i want. How can i invoke the factory on every request and override the existingUser entity?

      Thanx in advance.