title: Using OpenSessionInViewInterceptor to avoid LazyInitializationException
body: <p>First I need to acknowledge the fact that I'm new to EJB, JPA and Spring, so many of the things I believe as true could be wrong.</p>
  
  <p>I'm building an EJB application where there's an stateless session bean used to retrieve many JPA (Hibernate) entities. The problem, which I believe is a widespread problem, is that I cannot traverse the relationships of those entities when the stateless returns any instance. I get the dreaded LazyInitializationException. In many cases I found that using eager fetching I could avoid the exception, but this felt more like a workaround than a real fix. After lots of googling, I found that (since I'm using spring) probably the most intrusive way to accomplish this was using OpenSessionInViewInterceptor.</p>
  
  <p>Reading <a href="http://www.paulcodding.com/blog/2008/01/21/using-the-opensessioninviewinterceptor-for-spring-hibernate3/" rel="nofollow noreferrer" title="this">this</a> looks like it's easy to use, but I can't map the files mentioned in the article. One possible explanation is that I'm using Spring 3, so the names for the files might have changed. I do have a <em>spring3app-servlet.xml</em> where beans are being declared. I also have a <em>web.xml</em> where filters are set (this file I believe that was used with spring 2.0, but it still works with 3.0).</p>
  
  <p>Further searching made me realize that the filenames weren't my only concern, since I don't have any SessionFactory bean, which I believe it's necessary for this to work. This lead me to search info about the SessionFactory bean.</p>
  
  <p>That search made me realize that I probably need .hbm.xml files. I'm not sure if those files are really needed, or if they where a requisite for legacy hibernate-spring versions.</p>
  
  <p>tl;dr: I want an  OpenSessionInViewInterceptor. Do I need a SessionFactory Bean? Do I need .hbm.xml files? Where can I find all the information to set this up?</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Maybe the solution is using OpenSessionInViewFilter. I'm trying to use it but it still fails with the same exception. I'm reading <a href="http://forum.springsource.org/showthread.php?t=76488" rel="nofollow noreferrer" title="this">this</a> in search of a fix.</p>