'Fixing of Java.lang.IllegalStateException: No active conversation found. at com.rapidclipse.framework.server.jpa.Jpa.getEntityManager(Jpa.java:200)
I have a running RapidClipse X Project, in which I work with a MySQL Database. I created a class to copy data from one table into a second table. For this I use a stream
HibKontoDAO().findAll().stream().forEach( tc -> {
... copy data
}
The call and the process of this code works very well from anywhere in my application, except by calling it by a rest service.
Always when I call it via REST then I get following Error:
java.lang.IllegalStateException: No active conversation found.
at com.rapidclipse.framework.server.jpa.Jpa.getEntityManager(Jpa.java:200)
at com.rapidclipse.framework.server.jpa.Jpa.getEntityManager(Jpa.java:180)
What I did: I used for testing purpoase the simple Hello World example out of: https://www.javaguides.net/2020/01/resteasy-hello-world-example-tutorial.html
I placed the code in my application and it worked also very well! Then I changed it. In the HelloWorldResource class I call my code (which gives back a text)
String myUmsMes = this.StartTransfer();
final HlpHelloWorldRest helloWorld = new HlpHelloWorldRest(myUmsMes);
When I run this, I get in the Stream the error.
HibKontoDAO().findAll().stream().forEach( tc -> {
... copy data
}
The full stacktrace is:
Apr. 10, 2022 10:55:09 AM com.rieder.finmgmt.helper.HlpHelloWorldRestResource StartTransfer
INFO: com.rieder.finmgmt.helper.HlpHelloWorldRestResource Exception happend
java.lang.IllegalStateException: No active conversation found.
at com.rapidclipse.framework.server.jpa.Jpa.getEntityManager(Jpa.java:200)
at com.rapidclipse.framework.server.jpa.Jpa.getEntityManager(Jpa.java:180)
at com.rapidclipse.framework.server.jpa.dal.JpaDataAccessObject$Default.em(JpaDataAccessObject.java:173)
at com.rapidclipse.framework.server.jpa.dal.JpaDataAccessObject$Default.findAll(JpaDataAccessObject.java:243)
at com.rieder.finmgmt.helper.HlpHelloWorldRestResource.StartTransfer(HlpHelloWorldRestResource.java:89)
at com.rieder.finmgmt.helper.HlpHelloWorldRestResource.helloWorld(HlpHelloWorldRestResource.java:49)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:138)
at org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:546)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTargetAfterFilter(ResourceMethodInvoker.java:435)
at org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invokeOnTarget$0(ResourceMethodInvoker.java:396)
at org.jboss.resteasy.core.interception.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:358)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:398)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:365)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:338)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:440)
at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:229)
at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:135)
at org.jboss.resteasy.core.interception.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:358)
at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:138)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:215)
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:245)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:61)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:196)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:698)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:364)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:624)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:831)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1673)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:832)
Both codes runs fine if they runs alone. And I found nothing in web for the .... No active conversation found.....
Any idea what I did wrong, what could be the reason, or how to fix this? Thank you in advance!
Solution 1:[1]
I played a long time to find a way. It seems, that the inbuilt version of MyEntityDAO.findAll did not work, if you call it by rest. I had to create an own session. Therefore I created in my MyEntityDAO a small peace of code:
public List < MyEntity > getAll() {
try (Session session = this in my updateHibernateUtil.getSessionFactory().openSession()) {
return session.createQuery("from MyEntity", MyEntity.class).list();
}
}
And I had to create a HibernateUtil.class like described in: https://www.javaguides.net/2021/08/hibernate-example-with-mysql-database.html
Then I referenced it in my copy logic and everything worked fine!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |