You have to understand that the OpenSessionIn View filter is good only for that request. I assume you are accessing a dao which returns an entity object. Once the servlet request is over the session gets closed.
Let us say that you are retrieving an entity in a request don't call any associated method but persist your object in your session. At some other point you retrieve the object from your session then access the associated method you are sure to get the LazyInit error. The way to avoid that scenario is to add the below two methods to your utility class and call reassociate to attach the detatched object to the hibernate session and once your are done close the session.
Also if you are calling a session bean which access your dao then you will get the LazyInit error even if you set the filter. OpenSessionInView Filter keeps the session open for the duration of the request.
Read Karl Baum's weblog on this topic
Code:
public static org.hibernate.Session reassociateEntity(ServletContext sc,
Object obj) {
// Remember to call sessionFactoryUtils.closeSessionIfNecessary(
SessionFactory sessionFactory = (SessionFactory) WebApplicationContextUtils
.getWebApplicationContext(sc).getBean("sessionFactory");
org.hibernate.Session ses = SessionFactoryUtils.getSession(
sessionFactory, true);
ses.lock(obj, LockMode.NONE);
return ses;
}
public static void closeHibernateSession(ServletContext sc,org.hibernate.Session ses)
{
SessionFactory sessionFactory = (SessionFactory)WebApplicationContextUtils.getWebApplicationContext(sc).getBean("sessionFactory");
SessionFactoryUtils.closeSessionIfNecessary(ses,sessionFactory);
}