title: OpenEntityManagerInView equivalent for Junit and Quartz Jobs
body: <p>Is there any standard way (or substitute to <code>Open Session [EntityManager] in View</code>) for usage of classes that depend on Lazy Initialization <code>(fetch = FetchType.LAZY)</code> of entities in
  following two use-cases:</p>
  
  <ol>
  <li><p>In the JUnit test cases</p></li>
  <li><p>In quartz jobs</p></li>
  </ol>
  
  <p>For both the above scenarios OSIV pattern will not work as no web request enters the system. How to get Lazy Loading work in such situations?</p>
  
  <p>PS: Spring's <code>OpenEntityManagerInViewFilter</code> and <code>OpenEntityManagerInViewInterceptor</code> are both web request oriented. </p>
  
  <ol>
  <li>I can not prefetch all such relations/entites by doing a dummy <code>get</code> just to load it before session is closed in the repository(DAO).</li>
  <li>I know, for JUnit I can manually open/close EM in <code>@Before</code> / <code>@after</code>. But am looking for something more elegant and standard.</li>
  </ol>
  
  <p>Rerference :
  <a href="https://stackoverflow.com/questions/5263825/lazyinitializationexception-due-to-no-session-defined-in-parent-application-con">LazyInitializationException due to no session defined in &quot;parent&quot; application context in Hibernate 3 in a moduled Spring application using annotations</a></p>