title: Unable to refresh JPA 2 Entity injected into a JSF 2 Managed Bean
body: <p>I have a JSF managed bean in session scope that contains an entity to trace, for example, the authenticated user:</p>
  
  <pre><code>@ManagedBean
  @SessionScoped
  public class LoginController implements Serializable {
    User user;
  
    public User getUser() {
      return this.user;
    }
  
    public void setUser(User user) {
      this.user = user;
    }
    /* ... */
  }
  </code></pre>
  
  <p>In another bean I have to inject the user to use it to retrieve a list of roles in association with it, like this:</p>
  
  <pre><code>@ManagedBean
  @ViewScoped
  public class AnotherController implements Serializable {
  
    List&lt;Role&gt; roles;      
  
    @ManagedProperty(value="#{loginController.user}")
    User user;
  
    public someMethod() {
      /* Some stuff that insert other roles into database, referring the user as owner */
      roles = user.getRolesList();
    }
  }
  </code></pre>
  
  <p>If I update the page with ajax using <code>someMethod</code>, the <code>roles</code> list still not reload.
  If I insert <code>em.refresh(user)</code> before <code>user.getRolesList</code> I get this error:</p>
  
  <pre><code>Can not refresh not managed object: model.User[ id=1 ].
  </code></pre>
  
  <p>Can anyone help me to understand this? Why session scoped entity get not managed if injected into another bean? How can I fix this?
  Thank you.</p>