title: How can i get a session and avoid LazyInitialization Exception inside my Rest Layer?
body: <p>f got my application layer that works basically with spring+jsf(2.0) with primeFaces(3.5)+hibernate(4.3.5). Now we had to put a new way to access the DAO that goes outside the spring and the jsf, we have created a Rest path. The problem is: when i access my application with the browser and login first everything works correctly, including the Rest access to the DAO. The problem is when i try to access the Rest without the login. I tried to make a filter that intercept anything that goes through /rest/* path where i wrote:</p>
  
  <pre><code>@Override
    public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2)
        throws IOException, ServletException {
      HttpServletRequest req = (HttpServletRequest)arg0;
      HttpSession session = req.getSession(true);
      HttpSession session2 = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
      arg2.doFilter(arg0, arg1);
    }
  </code></pre>
  
  <p>But it doesn't work because the first session that i get is not the session that i want (it's outside the JSF context) and the first try to get the session from FacesContext gives me error because i'm outside JSF cycle that begins when i call something with *.jsf... the problem is that i can't call my Rest with a .jsp in the end and i can't get the data i need in DAO without the session. There is someway to bypass this problem?</p>