5 Replies Latest reply on Nov 29, 2007 9:42 AM by Jamie Cruise

    Getting JBPM to use the seam managed persistence context

    Jamie Cruise Newbie

      Is there any way of elimnating the hibernate.cfg.xml for jbpm? I am trying to implement a multi-tenant application, with separate database connections per customer. I can easily select the entityManagerFactory dynamically for the main application, but this doesn't change the process db. Which is not good.

      I did manage to patch the main jbpm component in seam to allow switching of configs at runtime, but this seems like a bit of a hack.

      It would be much easier if we could use a single persistence.xml file for process an other application data.

      Cheers
      J

        • 1. Re: Getting JBPM to use the seam managed persistence context
          Pete Muir Master

          IIRC jbpm still uses hibernate directly rather than using JPA. With this in mind I think you can't use persistence.xml, but maybe you can use a Seam managed session. Perhaps ask on the jbpm forum as I don't know if this is possible.

          • 2. Re: Getting JBPM to use the seam managed persistence context
            Jamie Cruise Newbie

            Ok. Do you have any interest in a patch to allow us to do something like this in components.xml:

            <bpm:jbpm name="config1" jbpm-configuration-name="jbpm-1.cfg.xml" />
            <bpm:jbpm name="config2" jbpm-configuration-name="jbpm-2.cfg.xml"/>
            <bpm:managed-jbpm-context name="jbpmContext" auto-create="true" jbpm-session-factory="#{jbpmConfiguration}" />
            


            where jbpmConfiguration would a reference to either config1 or config2

            Note that the current managed JbpmContext has a hard dependency on the default jbpm implementation because of code like this:

            jbpmContext = Jbpm.instance().getJbpmConfiguration().createJbpmContext();
            


            You can't just set the session context manually after getting the ManagedJbpmContext, nor can you replace the default implementation of ManagedJbpmContext without patching Seam because of code like this:

            ProcessInstance process = ManagedJbpmContext.instance().newProcessInstanceForUpdate(processDefinitionName);
            


            in the classes in org.jboss.seam.bpm.

            Thoughts appreciated.

            Cheers
            J

            • 3. Re: Getting JBPM to use the seam managed persistence context
              Pete Muir Master

               

              "jcruise" wrote:
              Note that the current managed JbpmContext has a hard dependency on the default jbpm implementation because of code like this:

              jbpmContext = Jbpm.instance().getJbpmConfiguration().createJbpmContext();
              


              I don't understand this statement - yes, it requires that Jbpm.instance().getJbpmConfiguration() returns an instance of org.jbpm.JbpmConfiguration - but that is the public API of the jbpm component (and I don't see a way around that), but there is no hard dependency to Jbpm there at all.

              You can't just set the session context manually after getting the ManagedJbpmContext, nor can you replace the default implementation of ManagedJbpmContext without patching Seam because of code like this:

              ProcessInstance process = ManagedJbpmContext.instance().newProcessInstanceForUpdate(processDefinitionName);
              


              Again, why not?

              (I think you haven't fully understand the precedence and component overriding rules of Seam).

              • 4. Re: Getting JBPM to use the seam managed persistence context
                Jamie Cruise Newbie

                OK. I assumed, perhaps erroneously, that the component overriding rules would only work if you looked up the component by name. I believed that this code would always return an instance of ManagedJbpmContext.

                 public static JbpmContext instance()
                 {
                 if ( !Contexts.isEventContextActive() )
                 {
                 throw new IllegalStateException("no active event context");
                 }
                 return (JbpmContext) Component.getInstance(ManagedJbpmContext.class, ScopeType.EVENT);
                 }
                



                Are you saying that I can install my own replacement for ManagedJbpmContext and that the ManagedJBpmContext.instance() call shown above would return my component?

                Cheers
                J

                • 5. Re: Getting JBPM to use the seam managed persistence context
                  Jamie Cruise Newbie

                  Ok.

                   public static Object getInstance(Class<?> clazz, ScopeType scope, boolean create)
                   {
                   return getInstance( getComponentName(clazz), scope, create );
                   }
                  



                  I can see that the static instance() call does ultimately result in retrieving the component by name.

                  Consider me educated now :)

                  Cheers
                  J