cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Carsten Ziegeler <cziege...@apache.org>
Subject Re: [HELP] SitemapEvenListener
Date Fri, 18 Apr 2008 07:38:42 GMT
I have no knowledge about this spring/hibernate stuff, but if your 
hibernate code is correct, it should work (ok, I know this doesn't help 
you). So, my question is if you're sure that your code in leftSitemap() 
should really get to the session created in enteredSitemap?. Could it be 
that internal cocoon requests are used and leftSitemap is called twice?
I remember that collegues of mine did the same and it worked for them.

HTH
Carsten


Patrick Heiden wrote:
> Hello together!
> 
> I am trying to implement an OpenSessionInViewInterceptor (OSIVI) using Cocoons (2.2)
Enter/LeaveSitemapEventListener. I have one class wich implements both Listener interfaces:
> 
> ...
> 
> public void enteredSitemap(EnterSitemapEvent event) {
>    log.debug("Opening Hibernate Session and beginning transaction.");
>    Session session = sessionFactory.openSession();
>    session.beginTransaction();
> 
>    TransactionSynchronizationManager.bindResource(
>              sessionFactory, new SessionHolder(session));
>    TransactionSynchronizationManager.initSynchronization();
> }
> 
> ...
> 
> public void leftSitemap(LeaveSitemapEvent event) {
>    Session session = sessionFactory.getCurrentSession();
>    try {
>       log.debug("Committing the database transaction.");
>       session.getTransaction().commit();
>    } catch ( RuntimeException ex ) {
>       try {
>          log.error( ex );
>          log.debug("Rolling back the database transaction.");
>          session.getTransaction().rollback();
>          if ( session.isOpen() ) {
>             session.close();
>          }
>       } catch ( RuntimeException e ) {
>          log.error( e );
>          throw e; // Let the exception propagate up the stack.
>       }
>    } finally {
>       try {
>          if ( session.isOpen() ) {
>             session.close();
>          }
>       } catch ( RuntimeException e ) { /* do nothing */ }
>       TransactionSynchronizationManager.unbindResource( sessionFactory );
>       TransactionSynchronizationManager.clearSynchronization();
>    }
> }
> 
> ...
> 
> I thought this would work, since i manually bind the session to the 'current' thread.
But after opening the session (and some DB Work wich is logged to stdout) I get following
Exception from out of leftSitemap( ... ):
> 
> org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration
does not allow creation of non-transactional one here
>         at org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63)
>         at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:544)
>         at de.ifado.isac.web.OpenSessionInViewInterceptor.leftSitemap(OpenSessionInViewInterceptor.java:70)
>         at org.apache.cocoon.components.treeprocessor.ConcreteTreeProcessor.process(ConcreteTreeProcessor.java:256)
>         at org.apache.cocoon.components.treeprocessor.ConcreteTreeProcessor.process(ConcreteTreeProcessor.java:171)
>         at org.apache.cocoon.components.treeprocessor.TreeProcessor.process(TreeProcessor.java:247)
>         at org.apache.cocoon.servlet.RequestProcessor.process(RequestProcessor.java:351)
>         at org.apache.cocoon.servlet.RequestProcessor.service(RequestProcessor.java:169)
>         at org.apache.cocoon.sitemap.SitemapServlet.service(SitemapServlet.java:84)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
>         at org.apache.cocoon.servletservice.ServletServiceContext$PathDispatcher.forward(ServletServiceContext.java:468)
>         at org.apache.cocoon.servletservice.ServletServiceContext$PathDispatcher.forward(ServletServiceContext.java:443)
>         at org.apache.cocoon.servletservice.spring.ServletFactoryBean$ServiceInterceptor.invoke(ServletFactoryBean.java:264)
>         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
>         at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
>         at $Proxy5.service(Unknown Source)
>         at org.apache.cocoon.servletservice.DispatcherServlet.service(DispatcherServlet.java:106)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
>         at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
>         at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1093)
>         at org.apache.cocoon.servlet.multipart.MultipartFilter.doFilter(MultipartFilter.java:131)
>         at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
>         at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
>         at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
>         at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
>         at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726)
>         at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
>         at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:206)
>         at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
>         at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
>         at org.mortbay.jetty.Server.handle(Server.java:324)
>         at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
>         at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:828)
>         at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514)
>         at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
>         at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
>         at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
>         at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:450)
> 
> I have registered the Listener throug a bean definition inside my blocks COB-INF/config/spring/listener.xml:
> 
> <bean id="openSessionInViewInterceptor" class="de.ifado.isac.web.OpenSessionInViewInterceptor">
>    <property name="sessionFactory" ref="sessionFactory" />
> </bean>
> 
> The SessionFactory is defined elsewhere (and retrieved after global WebAppCtx is build
through Cocoon/Spring.
> 
> I have no idea why my sessionContext gets lost!?
> 
> Help appreciated,
> greetings,
> Patrick


-- 
Carsten Ziegeler
cziegeler@apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message