Bob, you are right about the EnityManger being closed.  I spent quite a bit
of time looking into the error and the Spring forums say that the listener
(org.springframework.web.context.ContextLoaderListener) should work in the
same way.  Either way, I get the same error whether I use the listener or
the open view filter.


The ContextLoaderListener is Spring's bootstrap mechanism in web applications. In other words when the web application starts up, ContextLoaderListener will read your spring.xml file and create the Spring ApplicationContext. It won't open or close the EntityManager or commit transactions. So I'm fairly confident that ContextLoaderListener is not where the issue lies.

I still think the problem lies in the fact that you have the @Transactional annotation on your Repository. Btw I'm not saying that having @Transaction on the Repository is wrong, its just that it means the Transaction will commit whenever a method on Repository is invoked, and the session will get closed. If you want to use @Transactional on your Repository you basically need to know which entities to load eagerly.

I suggest you try the following and see what happens: declare the OpenEntityManagerInViewFilter in your web.xml. This filter binds an EntityManager instance to the thread for the duration of the request. However even if you have the filter, the @Transactional annotation will still commit the transaction (and close the session) after any Repository method is invoked. So try and remove the @Transactional annotation from the Repository and see what happens. Do you still get the lazy exception? Very likely something else will break but at least this should prove the theory of @Transactional :)

Let us know your findings.

kind regards

bob



BTW thanks for any assistance.

[Click] [error] handleException: org.hibernate.LazyInitializationException:
failed to lazily initialize a collection of role:
au.org.pheno.f1.domain.attendees.jpa.PrincipalJpa.registeredForEvents, no
session or session was closed
        at
org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
        at
org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
        at
org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343)
        at
org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
        at 
org.hibernate.collection.PersistentBag.toString(PersistentBag.java:483)
        at java.lang.String.valueOf(String.java:2838)
        at java.lang.StringBuffer.append(StringBuffer.java:236)
        at
org.apache.commons.lang.builder.ToStringStyle.appendDetail(ToStringStyle.java:590)
        at
org.apache.commons.lang.builder.ToStringStyle.appendInternal(ToStringStyle.java:465)
        at
org.apache.commons.lang.builder.ToStringStyle.append(ToStringStyle.java:428)
        at
org.apache.commons.lang.builder.ToStringBuilder.append(ToStringBuilder.java:840)
        at
org.apache.commons.lang.builder.ReflectionToStringBuilder.appendFieldsIn(ReflectionToStringBuilder.java:606)
        at
org.apache.commons.lang.builder.ReflectionToStringBuilder.toString(ReflectionToStringBuilder.java:759)
        at
org.apache.commons.lang.builder.ReflectionToStringBuilder.toString(ReflectionToStringBuilder.java:287)
        at
org.apache.commons.lang.builder.ReflectionToStringBuilder.toString(ReflectionToStringBuilder.java:121)
        at
org.apache.commons.lang.builder.ToStringBuilder.reflectionToString(ToStringBuilder.java:126)
        at
au.org.pheno.f1.domain.attendees.jpa.PrincipalJpa.toString(PrincipalJpa.java:655)
        at au.org.pheno.f1.test.pages.LoginPage.onInit(LoginPage.java:66)
        at org.apache.click.ClickServlet.processPage(ClickServlet.java:512)
        at org.apache.click.ClickServlet.handleRequest(ClickServlet.java:334)
        at org.apache.click.ClickServlet.doGet(ClickServlet.java:253)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
        at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
        at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
        at 
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
        at java.lang.Thread.run(Thread.java:636)

Reply via email to