title: Spring+Hibernate: could not initialize proxy no Session - What to do when an exception occured on a DAO?
body: <p>I got <code>could not initialize proxy no Session</code> exception on my JSP pages.</p>
  
  <p>Here is what I do;</p>
  
  <p>There are DAOs for Hibernate. These are not special classes. They just have autowired instances of Hibernate SessionFactory. Yes I use pure Hibernate to do my DB access.</p>
  
  <p>The functions on DAO classes are annotated with <code>@Transactional(rollBackFor=Exception.class)</code> and My spring configurations prepared accordingly. Also my entities/controllers are also configured with Annotations etc.</p>
  
  <p>I dont have a seperate Service classes layer. My Services and DAOs are overlapped. they are same. If a Service class need to access DB they are just annotated with <code>@Repository</code> rather than <code>@Service</code></p>
  
  <p>Until this error, everything was working perfectly. (I have hundreds of classes/DAOs/entities etc)</p>
  
  <p>Now, I need to call two DAO/Service functions at one of my controllers. I only call second DAO function when the first one throws an exception.</p>
  
  <p>I need to throw exceptions based on some conditions to rollback the changes made with first DAO call. The second call just to show some information from DB to the user who entered wrong input.</p>
  
  <p>I dont know why but the second DAO call is working, its gets classes from DB. then I forward this classes on to my Model attribute on my controllers so my JSPs can displays them.</p>
  
  <p>But when my JSP pages tries to access attributes of these classes I got the 
  <code>could not initialize proxy no Session</code> exception.</p>
  
  <p>So here is my question, what should I do to avoid this errors.</p>
  
  <p>Should I do something with hibernate transaction/session on the first DAO call?
  Because I do nothing. I just get a session and do get/save/update etc on it. I think <code>@Transactional</code> attribute will handle the transaction issues and <code>@Repository</code> attribute handles the session issues.</p>
  
  <hr>
  
  <p>I have already tried lazy/eager loading issue.
  I have already put <code>OpenSessionInViewFilter</code> filter on my configurations.</p>
  
  <p>But none of them solved my problem.</p>
  
  <p>Any advises/thoughts?</p>