Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-9177

combination of JPA-Component, loop and wiretap throws entitymanger cloesd exception

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 2.15.2, 2.15.3
    • 2.16.0, 2.15.4
    • camel-core, camel-jpa
    • None
    • Camel 2.15.2 with Spring-Boot 1.2.3.RELEASE (with camel xml dsl)

    • Unknown

    Description

      Hi,
      I have found 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:

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

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

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

      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.

      Attachments

        Issue Links

          Activity

            People

              davsclaus Claus Ibsen
              pschaerf Pascal S.
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: