Uploaded image for project: 'JBoss BPMS Platform'
  1. JBoss BPMS Platform
  2. RHBPMS-1616

javax.naming.NoInitialContextException when using JPA persistence with spring

XMLWordPrintable

      Platform BZ for https://issues.jboss.org/browse/JBPM-4369
      See attachments in that Jira above

      --------------------------
      I'm getting a:
      javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
      When trying to use JBPM with engine with spring transaction management.
      The call stack (simplified) that leads to the errors is as follows:
      1. org.jbpm.runtime.manager.impl.PerRequestRuntimeManager.getRuntimeEngine():66 creates a RuntimeEngine passing KieSession instantiated via the JPASessionFactory
      2. org.jbpm.runtime.manager.impl.factory.JPASessionFactory.newKieSession():42 creates a new KieSession using the RuntimeEnvironment that was initially injected
      3. The creation of the KieSession causes the invocation of org.drools.persistence.SingleSessionCommandService.initTransactionManager(Environment):267.
      Before the completion of this method, the original transaction manager and the PersistenceContextManager are replaced with instances of org.kie.spring.persistence.KieSpringJpaManager and org.kie.spring.persistence.KieSpringTransactionManager
      within the environment
      4. At later stage, one of the callback needed to initialize the RuntimeManger, will invoke org.jbpm.runtime.manager.impl.AbstractRuntimeManager.getTransactionManager():233.
      This will throw javax.naming.NoInitialContextException because the environment instance used by the AbstractRuntimeManager is not the same that was corrected by the SingleSessionCommandService in step 3.
      Reason for this is that on step 2, org.jbpm.runtime.manager.impl.SimpleRuntimeEnvironment.getEnvironment():150 is called and it causes the environment to be cloned rather than passed by reference.
      Would the solution to the problem be to change org.jbpm.runtime.manager.impl.factory.JPASessionFactory.newKieSession():42 so that it uses SimpleRuntimeEnvironment.getEnvironmentTemplate() instead?
      I attached part of my spring configuration for reference.

              swiderski.maciej Maciej Swiderski (Inactive)
              rhn-support-alazarot Alessandro Lazarotti
              Karel Suta Karel Suta
              Karel Suta Karel Suta
              Karel Suta, Kris Verlaenen, Marek Baluch
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: