title: Spring MVC : How to store user in the session and retrieve it?
body: <p>I have a login page where the user can log into myb application. When the user click on the button "log in", the request is processed by the following  controller :</p>
  
  <pre><code>@Controller
  @SessionAttributes("user-entity")
  public class LoginController extends BaseController {
  
      @RequestMapping(value="/login", method = RequestMethod.GET)    
      public ModelAndView login(WebRequest webRequest, @ModelAttribute("user") User user) {
          return  new ModelAndView(VIEW_LOGIN_NAME, "user-entity", user);
      }
  </code></pre>
  
  <p>In the above code, I have added the user-entity ( user ) in the session. But I am not able to retrieve the user-entity in another controller : </p>
  
  <pre><code>@Controller
  public class ProfileController extends BaseController{  
  @RequestMapping(value="/saveprofil", method = RequestMethod.POST)
  public ModelAndView saveProfile(@ModelAttribute Profil profil,HttpSession session){
      User user = (User) session.getAttribute("user-entity");
  
      user.setProfil(profil);
      userServices.createUser(user); 
      ModelAndView modelAndView = new ModelAndView();
      modelAndView.setViewName("saveProfilSuccess");
      return modelAndView;
  } 
  </code></pre>
  
  <p>The user object is not null but all attributes are null. What's wrong?</p>