views:

437

answers:

1

Hi all,

just a simple question about a great problem...

In my web app i use Struts, Spring and Hibernate.

I've a lot of Business (classes that edit the database with Hibernate), many action that interact with Business.

In Spring configuration i've inject SessionFactory in Business and the Business into Actions.

When I call a business all work.

When into the flow i return to business, Hibernate launch an exception. In Action I wanna retrive lazy object and Hibernate launch "failed to lazily initialize a collection - no session or session was closed".

There is a workaround?

+3  A: 

If you want to be able to access lazily loaded Hibernate objects in an action or view, you need an interceptor or filter to keep the session open until the end of the request. Spring supplies the OpenSessionInViewFilter to do this for you.

Nick