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

Hibernate4 version of SpringSessionContext.currentSession() does not create a session if TransactionSynchronizationManager does not contain one [SPR-11801] #16421

Closed
spring-projects-issues opened this issue May 16, 2014 · 1 comment
Assignees
Labels
in: core in: data status: duplicate

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented May 16, 2014

thiago andrade opened SPR-11801 and commented

Please, read this before delete the JIRA issue for being duplicated!!

There is as other JIRA issue that relates this problem BUT it relates it as an "improvement" and its clear that this cannot be considered as an ordinary improvement, I consider it as a serious bug. By the way there is A LOT of resources around the web of people searching for the solution of this (like this http://stackoverflow.com/questions/20500346/error-no-session-bound-to-current-thread-with-hibernate-4-and-spring-3). They are using this workaround (https://gist.github.com/nexdrew/6992329). The problem is that, as @Fabricio Carvalho said, ??The side effect caused by this approach is the overhead of creating and using a HibernateTransactionManager on simple queries. Not in resource consumption of the database, but in processing of the application server.??.

Here is the description of the issue

The Hibernate4 support of Spring 3.1 does not open and register a session in case of the method called is annotated with @Transactional(propagation = Propagation.SUPPORTS).
In this case HibernateTransactionManager.doBegin() is never called which is the only place where hibernate session is opened. The result is, that all read operations which do not require a transaction will fail because the call to SessionFactory.currentSession() will result in an exception.
The Hibernate3 implementation contains a fallback for this case in SessionFactoryUtils.doGetSession(...) which is missing in the corresponding Hibernate4 implementation of SpringSessionContext.currentSession().
If the transaction propagation is changed to REQUIRES_NEW everything is working fine.

The related JIRA issue is #13659


Affects: 3.1 GA, 3.2.1, 3.2.2, 3.2.5

Reference URL: http://stackoverflow.com/questions/20500346/error-no-session-bound-to-current-thread-with-hibernate-4-and-spring-3

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented May 17, 2014

Juergen Hoeller commented

Please don't duplicate issues that are still open; this just makes it harder to track them. If you'd like to escalate an issue, comment accordingly (as you did on #13659), which bumps it up to the top of the recently-updated list and raises our attention again.

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core in: data status: duplicate
Projects
None yet
Development

No branches or pull requests

2 participants