Struggling with LazyInitializationException
david.spark Apr 17, 2009 3:19 PMHi, I'm hoping someone can help me understand Seam and LIE.
I have this code:
FeedbackType attitude = webUser.getClientContact().getClient().getBranch().getClientFeedbackTypeAttitude(); for(EventStaff eventStaff : currentEvent.getEventStaff()){ for(StaffBooking staffBooking : eventStaff.getStaffBookings()){ for(StaffFeedback staffFeedback : staffBooking.getStaffFeedback()){ if(staffFeedback.getFeedbackType().getId().equals(attitude.getId())){ staffBooking.setTempFeedbackRating(0); } } } }
with the entity bean having the following decleration:
@OneToOne @JoinColumn(name="ClientFeedbackTypeAttitude") private FeedbackType clientFeedbackTypeAttitude;
In certain situations when I load the page that this code gets trigger from I get the following error:
13:53:56,442 ERROR [LazyInitializationException] could not initialize proxy - no Session org.hibernate.LazyInitializationException: could not initialize proxy - no Session at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:57) at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111) at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:166) at uk.co.splendid.sms.feedback.FeedbackType_$$_javassist_423.getId(FeedbackType_$$_javassist_423.java) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at javax.el.BeanELResolver.getValue(BeanELResolver.java:62) at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53) at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72) at org.jboss.el.parser.AstPropertySuffix.getValue(AstPropertySuffix.java:53) at org.jboss.el.parser.AstValue.getValue(AstValue.java:67) at org.jboss.el.parser.AstEqual.getValue(AstEqual.java:22) ... at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446) at java.lang.Thread.run(Thread.java:619) 13:53:56,458 ERROR [STDERR] 17-Apr-2009 13:53:56 com.sun.facelets.FaceletViewHandler handleRenderException SEVERE: Error Rendering View[/client/bookingTimesheet.xhtml] javax.faces.FacesException: javax.el.ELException: /client/bookingTimesheet.xhtml @103,137 rendered="#{staffFeedbackComment.feedbackType.id == webUser.clientContact.client.branch.clientFeedbackTypeComment.id}": Error reading 'id' on type uk.co.splendid.sms.feedback.FeedbackType_$$_javassist_423 at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:393) at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:276) at org.ajax4jsf.renderkit.html.RepeatRenderer$1.process(RepeatRenderer.java:53) at org.ajax4jsf.model.SequenceDataModel.walk(SequenceDataModel.java:101) at org.ajax4jsf.component.UIDataAdaptor.walk(UIDataAdaptor.java:1151) at org.ajax4jsf.renderkit.html.RepeatRenderer.encodeChildren(RepeatRenderer.java:59) at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837) at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:282) at org.ajax4jsf.renderkit.html.RepeatRenderer$1.process(RepeatRenderer.java:53) at org.ajax4jsf.model.SequenceDataModel.walk(SequenceDataModel.java:101) ...
I don't really understand what is happening here, I've tried various things but all I've managed to do is change the point at which the error shows up. It only happens when visiting the page after visiting the same page for an item that does not result in the first section of code being fully executed. It seems like a fairly standard error but I just can't figure out how to fix it.
Thanks
David