You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Pascal S. (JIRA)" <ji...@apache.org> on 2015/09/28 08:41:04 UTC

[jira] [Created] (CAMEL-9177) combination of JPA-Component, loop and wiretap throws entitymanger cloesd exception

Pascal S. created CAMEL-9177:
--------------------------------

             Summary: combination of JPA-Component, loop and wiretap throws entitymanger cloesd exception
                 Key: CAMEL-9177
                 URL: https://issues.apache.org/jira/browse/CAMEL-9177
             Project: Camel
          Issue Type: Bug
          Components: camel-core, camel-jpa
    Affects Versions: 2.15.3, 2.15.2
         Environment: Camel 2.15.2 with Spring-Boot 1.2.3.RELEASE (with camel xml dsl)
            Reporter: Pascal S.


Hi,
I have a problem regarding a wiretap and the camel-jpa component. I have a route with an async split through a wiretap. In each route, I use a jpa producer to persist an entity. The problem is, that the entitymanager was closed before the async routes can reach the end. The cause is, that the same entitymanager is used in the async routes. The main route reaches the end and closes the entitymanager.

E.g. like the following route:
{code}
<route id="mainRoute>
    <from uri="direct:restendpoint"/>
    ...
    <to uri="jpa:MyEntity"/>
    ...
    <loop copy="true">
        ...
        <wireTap uri="direct:asyncroute"/>
    </loop>
</route>

<route id="asyncRoute">
    <from uri="direct:asyncroute"/>
    ...
    <to uri="jpa:MyEntity"/>
    ...
</route>
{code}

I think a possible fix can be to check that the entitymanager is null or closed. If null or closed, create a new entitymanager.

{code}
public final class JpaHelper {
    ...
    public static EntityManager getTargetEntityManager(Exchange exchange, ...
        ...
        if (em == null || !em.isOpen()) {
            // create a new entity manager
            em = entityManagerFactory.createEntityManager();
        ...
        }
    }
    ...
}
{code}

Another solution can be in the wiretap. There where the exchange is copied, the "CamelEntityManager" property could be removed.

Currently, my quickfix is: At the beginning of the async route I remove the entitymanager from the exchange.




--
This message was sent by Atlassian JIRA
(v6.3.4#6332)