Hello,
I am using OSIVInterceptor and usually this works fine. However there are a couple of classes that intermittently throw hibernate lazy load exceptions even though they are wired to the OSIV. I also don't see anything that could be detaching my objects in the code. I don't see a log that the Hibernate session was closed before the error is thrown. Usually I see this logged when the OSIV closes the session.
Any help would be greatly appreciated!
web.xml
application-context.xmlCode:<filter> <filter-name>requestContextFilter</filter-name> <filter-class>org.springframework.web.filter.RequestContextFilter</filter-class> </filter> <filter-mapping> <filter-name>requestContextFilter</filter-name> <url-pattern>/dwr/*</url-pattern> </filter-mapping> <!-- The 'contextConfigLocation' parameter tells Spring's ContextLoaderListener which Spring configuration files to load. --> <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/application-context.xml </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>lp</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet>
Offending codeCode:<bean id="openSessionInViewInterceptor" class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor"> <property name="flushModeName"> <value>FLUSH_AUTO</value> </property> <property name="sessionFactory"> <ref bean="sessionFactory"/> </property> <property name="singleSession"> <value>true</value> </property> </bean> <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory"><ref local="sessionFactory"/></property> </bean> <!-- HIBERNATE STUFF --> <!-- LocalSessionFactoryBean loads one or more HIbernate mapping XML files to produce a Hibernate Session Factory --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"><ref local="dataSource"/></property> <property name="mappingResources"> <list> ...hbm.xmls mapped here </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect</prop> <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop> <prop key="hibernate.max_fetch_depth">3</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> <property name="lobHandler"><ref bean="oracleLobHandler"/></property> </bean>
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: org.austinisd.lp.db.model.Lesson.stages, no session or session was closedCode:public Lesson copyAndReturnNewLesson(Integer lessonIdToCopy, User user) throws Exception { Lesson newLesson = new Lesson(); Lesson lessonToCopy = mLessonDao.findById(lessonIdToCopy); Integer arcId = lessonToCopy.getArc().getId(); BeanUtils.copyProperties(newLesson, lessonToCopy); newLesson.setId(null); newLesson.setName(lessonToCopy.getName() + " (Copy)"); newLesson.setCreatedBy(null); newLesson.setCreatedDate(null); LPUtilities.setAuditColumns(user.getUserID().toString(), newLesson); newLesson.setAssessments(new ArrayList()); newLesson.setLessonTeks(new ArrayList()); newLesson.setRelatedLessonTeks(new ArrayList()); newLesson.setResources(new ArrayList()); newLesson.setStages(new ArrayList()); for(Resource res: lessonToCopy.getResources()) { newLesson.getResources().add(res); } this.addArc(newLesson, arcId); mLessonDao.save(newLesson); //**works if move here**// mLessonDao.flushHibSession(); for(LessonTeks lt: lessonToCopy.getLessonTeks()) { LessonTeks newLessonTeks = new LessonTeks(); BeanUtils.copyProperties(newLessonTeks, lt); newLessonTeks.setId(null); newLessonTeks.setLesson(newLesson); mLessonTeksDao.save(newLessonTeks); newLessonTeks.setStudentExpectations(new ArrayList()); mLessonDao.flushHibSession(); for(TeksStudentExpectation se: lt.getStudentExpectations()) { newLessonTeks.getStudentExpectations().add(se); } mLessonTeksDao.save(newLessonTeks); } for(RelatedLessonTeks rlt: lessonToCopy.getRelatedLessonTeks()) { RelatedLessonTeks newRelatedLessonTeks = new RelatedLessonTeks(); BeanUtils.copyProperties(newRelatedLessonTeks, rlt); newRelatedLessonTeks.setId(null); newRelatedLessonTeks.setLesson(newLesson); newRelatedLessonTeks.setStudentExpectations(new ArrayList()); mRelatedLessonTeksDao.save(newRelatedLessonTeks); } //BOMBS on next line with lazy load exception //The really STRANGE part is if I move the following block up to //**works if move here**//, I do not receive the exception for(Stage stg: lessonToCopy.getStages()) { Stage newStage = new Stage(); BeanUtils.copyProperties(newStage, stg); newStage.setId(null); newStage.setCreatedBy(null); newStage.setCreatedDate(null); LPUtilities.setAuditColumns(user.getUserID().toString(), newStage); newStage.setLesson(newLesson); mStageDao.save(newStage); } return newLesson; }
org.hibernate.collection.AbstractPersistentCollect ion.throwLazyInitializationException(AbstractPersi stentCollection.java:358)
org.hibernate.collection.AbstractPersistentCollect ion.throwLazyInitializationExceptionIfNotConnected (AbstractPersistentCollection.java:350)
org.hibernate.collection.AbstractPersistentCollect ion.initialize(AbstractPersistentCollection.java:3 43)
org.hibernate.collection.AbstractPersistentCollect ion.read(AbstractPersistentCollection.java:86)
org.hibernate.collection.PersistentBag.iterator(Pe rsistentBag.java:246)
org.austinisd.lp.service.managers.LessonManager.co pyAndReturnNewLesson(LessonManager.java:154)
org.austinisd.lp.web.controllers.CopyLessonControl ler.handle(CopyLessonController.java:41)
org.springframework.web.servlet.mvc.AbstractComman dController.handleRequestInternal(AbstractCommandC ontroller.java:84)
org.springframework.web.servlet.mvc.AbstractContro ller.handleRequest(AbstractController.java:153)
org.springframework.web.servlet.mvc.SimpleControll erHandlerAdapter.handle(SimpleControllerHandlerAda pter.java:48)
org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:874)
org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:808)
org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:476)
org.springframework.web.servlet.FrameworkServlet.d oGet(FrameworkServlet.java:431)
javax.servlet.http.HttpServlet.service(HttpServlet .java:690)
javax.servlet.http.HttpServlet.service(HttpServlet .java:803)
org.austinisd.lp.framework.LoginCheckFilter.doFilt er(LoginCheckFilter.java:142)


Reply With Quote
