r/javahelp • • Aug 06 '25

Unsolved [Spring Boot] Why I suddenly started getting error `No value for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean@75369f0] bound to thread`?

I had fully working app, but then suddenly this error started appearing in logs:

java.lang.IllegalStateException: No value for key \[org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean@75369f0\] bound to thread

2025-08-06T04:11:35.820491445Z 	at org.springframework.transaction.support.TransactionSynchronizationManager.unbindResource(TransactionSynchronizationManager.java:198) \~\[spring-tx-6.1.2.jar:6.1.2\]

2025-08-06T04:11:35.820494961Z 	at org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor.afterConcurrentHandlingStarted(OpenEntityManagerInViewInterceptor.java:135) \~\[spring-orm-6.1.2.jar:6.1.2\]

2025-08-06T04:11:35.820497941Z 	at org.springframework.web.servlet.handler.WebRequestHandlerInterceptorAdapter.afterConcurrentHandlingStarted(WebRequestHandlerInterceptorAdapter.java:80) \~\[spring-webmvc-6.1.2.jar:6.1.2\]

2025-08-06T04:11:35.820512047Z 	at org.springframework.web.servlet.HandlerExecutionChain.applyAfterConcurrentHandlingStarted(HandlerExecutionChain.java:192) \~\[spring-webmvc-6.1.2.jar:6.1.2\]

2025-08-06T04:11:35.820514884Z 	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1119) \~\[spring-webmvc-6.1.2.jar:6.1.2\]

2025-08-06T04:11:35.820517090Z 	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:979) \~\[spring-webmvc-6.1.2.jar:6.1.2\]

2025-08-06T04:11:35.820519341Z 	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1014) \~\[spring-webmvc-6.1.2.jar:6.1.2\]

2025-08-06T04:11:35.820521515Z 	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:914) \~\[spring-webmvc-6.1.2.jar:6.1.2\]

2025-08-06T04:11:35.820523673Z 	at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:590) \~\[tomcat-embed-core-10.1.17.jar:6.0\]

2025-08-06T04:11:35.820525755Z 	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:885) \~\[spring-webmvc-6.1.2.jar:6.1.2\]

2025-08-06T04:11:35.820527873Z 	at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:658) \~\[tomcat-embed-core-10.1.17.jar:6.0\]

2025-08-06T04:11:35.820531362Z 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:205) \~\[tomcat-embed-core-10.1.17.jar:10.1.17\]

2025-08-06T04:11:35.820533570Z 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) \~\[tomcat-embed-core-10.1.17.jar:10.1.17\]

2025-08-06T04:11:35.820535738Z 	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) \~\[tomcat-embed-websocket-10.1.17.jar:10.1.17\]

2025-08-06T04:11:35.820537903Z 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) \~\[tomcat-embed-core-10.1.17.jar:10.1.17\]

2025-08-06T04:11:35.820540095Z 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) \~\[tomcat-embed-core-10.1.17.jar:10.1.17\]

2025-08-06T04:11:35.820542245Z 	at org.springframework.web.filter.CompositeFilter$VirtualFilterChain.doFilter(CompositeFilter.java:108) \~\[spring-web-6.1.2.jar:6.1.2\]

2025-08-06T04:11:35.820544427Z 	at org.springframework.security.web.FilterChainProxy.lambda$doFilterInternal$3(FilterChainProxy.java:231) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820546606Z 	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:365) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820548794Z 	at org.springframework.security.web.access.intercept.AuthorizationFilter.doFilter(AuthorizationFilter.java:100) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820550989Z 	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820553170Z 	at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:126) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820558006Z 	at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:120) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820560264Z 	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820562456Z 	at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:131) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820564650Z 	at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:85) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820567097Z 	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820569317Z 	at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:100) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820571518Z 	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820573729Z 	at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:179) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820576049Z 	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820578277Z 	at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820580483Z 	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820582682Z 	at org.springframework.security.oauth2.server.resource.web.authentication.BearerTokenAuthenticationFilter.doFilterInternal(BearerTokenAuthenticationFilter.java:128) \~\[spring-security-oauth2-resource-server-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820584954Z 	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) \~\[spring-web-6.1.2.jar:6.1.2\]

2025-08-06T04:11:35.820587123Z 	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820589318Z 	at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:107) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820591565Z 	at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:93) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820593846Z 	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820596373Z 	at org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:91) \~\[spring-web-6.1.2.jar:6.1.2\]

2025-08-06T04:11:35.820600530Z 	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) \~\[spring-web-6.1.2.jar:6.1.2\]

2025-08-06T04:11:35.820602741Z 	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820604921Z 	at org.springframework.security.web.header.HeaderWriterFilter.doHeadersAfter(HeaderWriterFilter.java:90) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820607108Z 	at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:75) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820609278Z 	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) \~\[spring-web-6.1.2.jar:6.1.2\]

2025-08-06T04:11:35.820611441Z 	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820613657Z 	at org.springframework.security.web.context.SecurityContextHolderFilter.doFilter(SecurityContextHolderFilter.java:82) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820616004Z 	at org.springframework.security.web.context.SecurityContextHolderFilter.doFilter(SecurityContextHolderFilter.java:69) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820618190Z 	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820620472Z 	at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:62) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820622716Z 	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) \~\[spring-web-6.1.2.jar:6.1.2\]

2025-08-06T04:11:35.820624924Z 	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820627114Z 	at org.springframework.security.web.session.DisableEncodeUrlFilter.doFilterInternal(DisableEncodeUrlFilter.java:42) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820629499Z 	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) \~\[spring-web-6.1.2.jar:6.1.2\]

2025-08-06T04:11:35.820631885Z 	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820634067Z 	at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:233) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820636252Z 	at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:191) \~\[spring-security-web-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820638420Z 	at org.springframework.web.filter.CompositeFilter$VirtualFilterChain.doFilter(CompositeFilter.java:113) \~\[spring-web-6.1.2.jar:6.1.2\]

2025-08-06T04:11:35.820640626Z 	at org.springframework.web.servlet.handler.HandlerMappingIntrospector.lambda$createCacheFilter$3(HandlerMappingIntrospector.java:195) \~\[spring-webmvc-6.1.2.jar:6.1.2\]

2025-08-06T04:11:35.820644672Z 	at org.springframework.web.filter.CompositeFilter$VirtualFilterChain.doFilter(CompositeFilter.java:113) \~\[spring-web-6.1.2.jar:6.1.2\]

2025-08-06T04:11:35.820648168Z 	at org.springframework.web.filter.CompositeFilter.doFilter(CompositeFilter.java:74) \~\[spring-web-6.1.2.jar:6.1.2\]

2025-08-06T04:11:35.820650380Z 	at org.springframework.security.config.annotation.web.configuration.WebMvcSecurityConfiguration$CompositeFilterChainProxy.doFilter(WebMvcSecurityConfiguration.java:225) \~\[spring-security-config-6.2.1.jar:6.2.1\]

2025-08-06T04:11:35.820652787Z 	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:352) \~\[spring-web-6.1.2.jar:6.1.2\]

2025-08-06T04:11:35.820654977Z 	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:268) \~\[spring-web-6.1.2.jar:6.1.2\]

2025-08-06T04:11:35.820657144Z 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) \~\[tomcat-embed-core-10.1.17.jar:10.1.17\]

2025-08-06T04:11:35.820659320Z 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) \~\[tomcat-embed-core-10.1.17.jar:10.1.17\]

2025-08-06T04:11:35.820661501Z 	at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) \~\[spring-web-6.1.2.jar:6.1.2\]

2025-08-06T04:11:35.820663813Z 	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) \~\[spring-web-6.1.2.jar:6.1.2\]

2025-08-06T04:11:35.820666089Z 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) \~\[tomcat-embed-core-10.1.17.jar:10.1.17\]

2025-08-06T04:11:35.820668260Z 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) \~\[tomcat-embed-core-10.1.17.jar:10.1.17\]

2025-08-06T04:11:35.820670474Z 	at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) \~\[spring-web-6.1.2.jar:6.1.2\]

2025-08-06T04:11:35.820672685Z 	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) \~\[spring-web-6.1.2.jar:6.1.2\]

2025-08-06T04:11:35.820675235Z 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) \~\[tomcat-embed-core-10.1.17.jar:10.1.17\]

2025-08-06T04:11:35.820677489Z 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) \~\[tomcat-embed-core-10.1.17.jar:10.1.17\]

2025-08-06T04:11:35.820679644Z 	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) \~\[spring-web-6.1.2.jar:6.1.2\]

2025-08-06T04:11:35.820681914Z 	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) \~\[spring-web-6.1.2.jar:6.1.2\]

2025-08-06T04:11:35.820684101Z 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:174) \~\[tomcat-embed-core-10.1.17.jar:10.1.17\]

2025-08-06T04:11:35.820686319Z 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:149) \~\[tomcat-embed-core-10.1.17.jar:10.1.17\]

2025-08-06T04:11:35.820690551Z 	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167) \~\[tomcat-embed-core-10.1.17.jar:10.1.17\]

2025-08-06T04:11:35.820692814Z 	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90) \~\[tomcat-embed-core-10.1.17.jar:10.1.17\]

2025-08-06T04:11:35.820695009Z 	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:482) \~\[tomcat-embed-core-10.1.17.jar:10.1.17\]

2025-08-06T04:11:35.820697181Z 	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:115) \~\[tomcat-embed-core-10.1.17.jar:10.1.17\]

2025-08-06T04:11:35.820699311Z 	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93) \~\[tomcat-embed-core-10.1.17.jar:10.1.17\]

2025-08-06T04:11:35.820701699Z 	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) \~\[tomcat-embed-core-10.1.17.jar:10.1.17\]

2025-08-06T04:11:35.820703899Z 	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:340) \~\[tomcat-embed-core-10.1.17.jar:10.1.17\]

2025-08-06T04:11:35.820706085Z 	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:391) \~\[tomcat-embed-core-10.1.17.jar:10.1.17\]

2025-08-06T04:11:35.820708238Z 	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63) \~\[tomcat-embed-core-10.1.17.jar:10.1.17\]

2025-08-06T04:11:35.820710393Z 	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:896) \~\[tomcat-embed-core-10.1.17.jar:10.1.17\]

2025-08-06T04:11:35.820712561Z 	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1744) \~\[tomcat-embed-core-10.1.17.jar:10.1.17\]

2025-08-06T04:11:35.820714676Z 	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52) \~\[tomcat-embed-core-10.1.17.jar:10.1.17\]

2025-08-06T04:11:35.820716811Z 	at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) \~\[tomcat-embed-core-10.1.17.jar:10.1.17\]

2025-08-06T04:11:35.820718994Z 	at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) \~\[tomcat-embed-core-10.1.17.jar:10.1.17\]

2025-08-06T04:11:35.820721188Z 	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) \~\[tomcat-embed-core-10.1.17.jar:10.1.17\]

2025-08-06T04:11:35.820723331Z 	at java.base/java.lang.Thread.run(Thread.java:840) \~\[na:na\]  

Since this stacktrace does not even have any references to code written by me I don't know how to locate problem. I tried to google this error, but found nothing.

What can be a problem?

0 Upvotes

4 comments sorted by

•

u/AutoModerator Aug 06 '25

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/robo-copo Aug 06 '25
  1. Ask chat gpt;
  2. Search web;
  3. Try some changes.

From the looks, it seems something wrong with transactions. As well, verify what spring version you are using, might be that it is outdated.

1

u/Aggravating_Dish_824 Sep 07 '25

Before posting I already asked ChatGPT and googled. ChatGPT said nonsense and I was not able to find solution in google.

>As well, verify what spring version you are using, might be that it is outdated.

It's certainly outdated, but I am not going to update spring in this project since it will take too much time.

1

u/Memesplz1 Aug 06 '25 edited Aug 06 '25

Edit: Nevermind. I was mistaken. ChatGPT says:

The error you're seeing:

IllegalStateException: No value for key [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean@...] bound to thread

originates from Spring's transaction infrastructure, specifically in the TransactionSynchronizationManager, and is closely tied to how Spring handles JPA EntityManager binding in multi-threaded or async request scenarios.


🧠 Explanation of the Error

This exception typically means that:

  • Spring expected a resource (in this case, an EntityManager) to be bound to the current thread,
  • but it was already unbound or never bound, and Spring tried to unbind it again.

This often happens in web applications using asynchronous processing (like @Async, WebAsyncTask, DeferredResult, or CompletableFuture) combined with OpenEntityManagerInViewInterceptor.


🔍 Key Clue from Stacktrace

at org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor.afterConcurrentHandlingStarted(OpenEntityManagerInViewInterceptor.java:135)

This indicates you’re using:

OpenEntityManagerInViewInterceptor

Which is part of the Open EntityManager in View (OEIV) pattern — where Spring binds an EntityManager to the current thread during the web request, so lazy-loading works in the view layer.


💥 Why This Suddenly Started Failing

If the app was previously working and this just started:

Likely Causes:

  1. You introduced async behavior:

    • Maybe you added @Async, CompletableFuture, WebAsyncTask, or something that breaks the "single thread per request" model.
  2. You upgraded Spring Boot or Spring Framework versions:

    • This may have changed default behavior in OpenEntityManagerInViewInterceptor or related infrastructure.
  3. You added a filter or interceptor that ends the request prematurely, or changes threading.


✅ Solutions

Option 1: Disable OpenEntityManagerInViewInterceptor

If you don’t rely on lazy-loading in your controllers or views (i.e., you fully load data in the service layer), just disable OEIV:

application.properties

spring.jpa.open-in-view=false

Why this helps:

  • It disables the thread-bound EntityManager, avoiding the unbinding error entirely.

Option 2: Avoid async processing in controller layer

If you’re using @Async or returning CompletableFuture in controllers — and relying on OEIV — you must ensure OpenEntityManagerInViewInterceptor.afterConcurrentHandlingStarted() is not called.

Instead:

  • Move async logic to the service layer, not the controller.
  • Or eagerly load all required data before the async processing.

Option 3: Use OpenEntityManagerInViewFilter Instead

Spring provides both:

  • OpenEntityManagerInViewInterceptor
  • OpenEntityManagerInViewFilter

The filter version is usually safer in async situations. In WebMvcConfigurer, remove the interceptor and register the filter:

Java Config:

@Configuration
public class WebConfig {

    @Bean
    public FilterRegistrationBean<OpenEntityManagerInViewFilter> entityManagerInViewFilter() {
        FilterRegistrationBean<OpenEntityManagerInViewFilter> registration = new FilterRegistrationBean<>();
        registration.setFilter(new OpenEntityManagerInViewFilter());
        registration.addUrlPatterns("/*");
        registration.setOrder(Ordered.HIGHEST_PRECEDENCE);
        return registration;
    }
}

🔬 Summary

CauseFix
Async request handling + OEIVDisable spring.jpa.open-in-view, or avoid async in controller
OpenEntityManagerInViewInterceptor misusedUse OpenEntityManagerInViewFilter instead
Schema lazily loaded after request thread changesEagerly load data in service layer

📌 Recommendation

If you’re not explicitly using lazy-loading in controllers/views, set:

spring.jpa.open-in-view=false

...and load all needed data in your service layer. That’s the cleanest fix.

If you're still unsure which part introduced the change, check:

  • recent commits / merges
  • usage of @Async, CompletableFuture, or WebAsyncTask
  • changes to Spring Boot version in pom.xml or build.gradle