Uploaded image for project: 'jBPM'
  1. jBPM
  2. JBPM-4369

javax.naming.NoInitialContextException when using JPA persistence with spring

XMLWordPrintable

      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)
            aledibe Alessandro Di Bella (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: