i'm having big trouble with getting the OpenSessionInViewFilter working, using Spring 3.0.2, hibernate3 and jsf2.
the scenario:
there is a BusinessCaseEntity with holding some simple information properties (of string and int type) and a list of mapped EmployeeEntities. This list is mapped with
fetch=FetchType.LAZY
first of all, i load a list of all BusinessCases and show them in a table. for this purpose, i use a dao class. the businesscases with their simple properties are displayed. if i select a specific businesscase i want to show the connected employees for instance. therefore i just want to use the getter method of the businesscase object --> getEmployees()
with my simple understanding of spring and hibernate, i know that the BusinessCaseEntity at this time is detached from any spring and hibernate(session) at the backend and the famous LazyLoadingException appears.
this is where i think that the OpenSessionInViewFilter comes in place. i read a lot of instructions of how to use it, but i still could not manage to get it working in my app.
configured the filter in my web.xml and i made a little subclass of the OpenSessionInViewFilter of spring to do some output for debugging purpose.
nevertheless, when it comes to the point to fetch the required data, the filter opens a new session, then an LazyLoadException is thrown and then the filter closes the session. why is there a LazyLoadException when the session is currently open?
2011-06-14 19:19:49,734 DEBUG HibernateFilter:239 - Using SessionFactory 'sessionFactory' for OpenSessionInViewFilter
2011-06-14 19:19:49,734 DEBUG HibernateFilter:66 - Opening single Hibernate Session in OpenSessionInViewFilter
Jun 14, 2011 7:19:49 PM com.sun.facelets.FaceletViewHandler handleRenderException
SEVERE: Error Rendering View[/web/caseDetails.xhtml]
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.frivak.cat.db.entities.BusinessCaseEntity.caseClientList, no session or session was closed
at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:383)
LOTS OF STACKTRACE ...
2011-06-14 19:19:49,879 DEBUG HibernateFilter:92 - Closing single Hibernate Session in OpenSessionInViewFilter
do i somehow misunderstand the purpose of the OpenSessionInViewFilter?
i am quite lost now and would really appreciate some help.
thanks - chris