-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Open Session In View filter and Struts Tiles
PostPosted: Mon Nov 01, 2004 8:21 am 
Newbie

Joined: Fri Apr 30, 2004 7:12 am
Posts: 4
Hi there ... :-)

I have a hopefully quick question regarding the Open Session In View Filter.

I have an application built using Struts and Tiles, which gets a JSP page of data through Hibernate.

Because I need to get a lazy-loaded list on the page, I use the Open Session In View filter to maintain the session when the view is being rendered. Now the problem is that I get this exception thrown every so often.


if (hibernateHolder.get() != null) {
throw new IllegalStateException("A session is already associated with this thread! "
+ "Someone must have called getSession() outside of the context "
+ "of a servlet request.");
}


So it looks like the session sometimes does not get closed at the end of the page render.

In the end I just changed the code to just close the session if it found it open when the request starts, but I'm not sure that is the best solution.

I was wondering if there are cases when the session doesn't close immediately on request, or perhaps its something to do with Struts-Tiles.

Has anyone else come across this?

------------------------------------------------------
[b]Hibernate version:[/b]
Hibernate 2.1

[b]Full stack trace of any exception that occurs:[/b]
2004-11-01 11:22:00 StandardWrapperValve[school]: Servlet.service() for servlet school threw exception
java.lang.IllegalStateException: A session is already associated with this thread! Someone must have called getSession() outside of the context of a servlet request.
at com.starstream.school.utils.database.SessionManager.doFilter(SessionManager.java:60)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:213)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:700)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:584)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)

[b]Name and version of the database you are using:[/b]
MySQL 3.23.37

-------------------------------------------------------------------------


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 01, 2004 8:49 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Threads are pooled on webserver, probably you forget to set null to "hibernateHolder" at the end of request, do it in "finally" block.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 01, 2004 9:14 am 
Newbie

Joined: Fri Apr 30, 2004 7:12 am
Posts: 4
[quote="baliukas"]Threads are pooled on webserver, probably you forget to set null to "hibernateHolder" at the end of request, do it in "finally" block.[/quote]

I've got this for my doFilter method:

[code] public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {

if (hibernateHolder.get() != null) {
throw new IllegalStateException("A session is already associated with this thread! "
+ "Someone must have called getSession() outside of the context "
+ "of a servlet request.");
}

try {
chain.doFilter(request, response);
}
finally {
closeSession();
}
}[/code]

I thought that the doFilter handled all the session closing.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.