Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
spring-issuemaster opened this issue Feb 19, 2014 · 4 comments

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Feb 19, 2014

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:

  • #16072 Load Time Weaving not working after upgrading Tomcat from 7.0.50 to 7.0.52
  • #15414 Use Tomcat 8's new instrumentable WebappClassLoader

2 votes, 2 watchers

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Feb 19, 2014

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

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Feb 19, 2014

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.

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Dec 24, 2015

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!!

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jan 12, 2019

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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.