views:

381

answers:

1

Totally new to Spring & Java development but working on a project for a class with some experienced developers. I believe we're using Spring MVC as our web layer(but I'm a C# guy so I may be mistaken in that regard). We have a view that gets an object with lazily loaded properties -- pretty straightforward stuff. Yet when I call one of these properties within a JSF view, I get this error:

failed to lazily initialize a collection of role: xxxxxxxx, 
  no session or session was closed

which makes me think that the hibernate session is being closed much too early. Is there a way to have one entitymanager that stays alive for the duration of the request, including after the model is sent to the view for rendering?

+2  A: 

Spring provides the OpenEntityManagerInViewFilter and OpenEntityManagerInViewInterceptor. They are the EntityManager version of the OpenSessionInView (OSIV) paradigm

Bozho
Works like a charm. Now to convince my compatriots that it's worth doing.
roufamatic