Skip to content

Hibernate session cannot be found after upgrading Tomcat from 7.0.50 to 8.0.3 [SPR-11447] #16073

Closed

Description

@spring-projects-issues

Holger Stenzhorn opened SPR-11447 and commented

My web application uses a combination of Spring with Hibernate (currently at 4.2.8). In the application context, I define the following:

<context:load-time-weaver/>
<context:spring-configured/>
<context:annotation-config/>
<context:component-scan base-package="org.obtima"
                        scoped-proxy="targetClass"/>
<tx:annotation-driven mode="aspectj"/>

This is working as expected until Tomcat 7.0.50. But when I deploy on 8.0.3 the first attempt to access the database, i.e. when I am trying to login to the application, fails:

19-Feb-2014 16:27:24.083 SEVERE [http-nio-8084-exec-12] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [default] in context with path [/test] threw exception
 org.hibernate.HibernateException: No Session found for current thread
	at org.springframework.orm.hibernate4.SpringSessionContext.currentSession(SpringSessionContext.java:97)
	at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:992)

After removing mode="aspectj" from <tx:annotation-driven/> the above mentioned login works and so the session was obviously found then (but code marked with @Transactional fails now).


Affects: 3.2.8

Issue Links:

2 votes, 2 watchers

Activity

  1. spring-projects-issues commented on Feb 19, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    This is probably due to load-time weaving generally not working, as in #16072. Try removing any spring-instrument jars, use a recent Spring version, and let context:load-time-weaver/ autodetect Tomcat's new built-in instrumentation capabilities. This should work out of the box now, without any special Tomcat setup. Unfortunately, old Spring Tomcat extensions can get in the way here :-(

    Juergen

  2. spring-projects-issues commented on Feb 19, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Holger Stenzhorn commented

    I have performed some additional testing on Tomcat 8.0.3 (also in relation to issue #16072) using three test cases:

    • Specify -javaagent:/some/path/to/spring-instrument-3.2.8.RELEASE.jar"
    • Copy spring-instrument-tomcat-3.2.8.RELEASE.jar to Tomcat's lib folder and specify org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader in my webapp's META-INF/context.xml
    • Do none of the two points above

    The result is that my webapp only works (completely) for the second test case above and so I evaluated the other two test cases a bit more:

    Checking the (same-looking) logs for those two test cases, it seems that the javaagent specification is simply ignored and Tomcat's own instrumentable (since 8.0.x) WebappClassLoader is used in both cases (see also #16072):

    INFO [org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver] - The ClassLoader [org.apache.catalina.loader.WebappClassLoader] does NOT provide a 'getThrowawayClassLoader()' method; SimpleThrowawayClassLoader will be used instead.
    INFO [org.springframework.context.weaving.DefaultContextLoadTimeWeaver] - Using a reflective load-time weaver for class loader: org.apache.catalina.loader.WebappClassLoader
    INFO [localhost-startStop-1] org.apache.catalina.loader.WebappClassLoader.addTransformer Added class file transformer [org.springframework.context.weaving.AspectJWeavingEnabler$AspectJClassBypassingClassFileTransformer@6c86b58b] to web application [/test].
    

    So in my initial report, I mention that after removing mode="aspectj" from <tx:annotation-driven/> I am able to login but I forgot to explicitly mention that all regular annotated Spring beans (e.g. @Component @Scope("session")) were actually found.

    Therefore I testing now to...

    • re-add <tx:annotation-driven mode="aspectj"/> to the application context
    • remove the mentioned database access marked with @Transactional and triggered by an ApplicationListener<ApplicationEvent>/AuthenticationSuccessEvent
    • add the following test bean
    @Component
    @Scope("session")
    public class TestBean {
      public String getHelloWorld() {
        return "Hello World!!!";
      }
    }
    
    • call this method from the welcome page with #{testBean.helloWorld}

    The result is successful in that I could log in and the welcome page showed the message from #{testBean.helloWorld}. Therefore the load time weaving employing Tomcat's own instrumentable WebappClassLoader seems to work in general.

    BUT as soon as I now call any database method marked as @Transactional then I get the exception No Session found for current thread.

  3. spring-projects-issues commented on Dec 24, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Pratheesh TU commented

    Same issue is happening with us, which is blocking us to deploy our application to Tomcat 8.0. Please resolve this issue!!

  4. added
    type: bug
    status: waiting-for-triage
    and removed
    type: bug
    on Jan 11, 2019
  5. added
    status: bulk-closed
    and removed
    status: waiting-for-triage
    on Jan 11, 2019
  6. spring-projects-issues commented on Jan 12, 2019

    @spring-projects-issues
    CollaboratorAuthor

    Bulk closing outdated, unresolved issues. Please, reopen if still relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: bulk-closed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions