5 Replies Latest reply on Oct 10, 2013 1:21 AM by mdegan

    Getting persistence.xml error while integrating jBPM 5.4 into a J2EE web app




      I have been having trouble getting "jBPM integrated into a web app" while using Eclipse (Kepler).  As a test I am simply trying to replicate the code found in the jBPM Full Installer's evaluation sample into the template code produced by a Maven JavaEE6 Archetype.  I have noted my steps below so that the problem can be easily reproduced.


      1) Add to the JBoss standalone.xml:

      <datasource jndi-name="java:jboss/jdbc/jbpm-ds" pool-name="jBPMDS" enabled="true" use-java-context="true">









      2) JBoss Central > Maven Project > filter on "javaee6" (to create the "myservlet" Project):

          Archetype = jboss-javaee6-webapp

          Accept all defaults


      3) Set src\main\resources\META-INF\persistence.xml to contain:

      <?xml version="1.0" encoding="UTF-8"?>

      <persistence version="2.0"

         xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"




         <persistence-unit name="primary">

            <!-- If you are running in a production environment, add a managed

               data source, the example data source is just for proofs of concept! -->



               <!-- Properties for Hibernate -->

               <property name="hibernate.hbm2ddl.auto" value="create-drop" />

               <property name="hibernate.show_sql" value="false" />





      4) Add a jBPM Runtime by pointing at the \runtime folder from the jBPM Full Installer.


      5) Select the jBPM Perspective, right click the myservlet Project > Convert to jBPM Project.


      6) Add to the Deployment Assembly the Java Build Path Entries > jBPM Library.


      7) In src\main\java\com\mycompany\mywebapp\controller add to (arbitrarily chosen) MemberRegistration.java (which was automatically created as part of the Project) the following which comes from the evaluation sample code:

      import java.util.HashMap;

      import java.util.Map;

      import org.drools.KnowledgeBase;

      import org.drools.builder.KnowledgeBuilder;

      import org.drools.builder.KnowledgeBuilderFactory;

      import org.drools.builder.ResourceType;

      import org.drools.io.ResourceFactory;

      import org.drools.logger.KnowledgeRuntimeLogger;

      import org.drools.logger.KnowledgeRuntimeLoggerFactory;

      import org.drools.runtime.StatefulKnowledgeSession;

      import org.jbpm.process.workitem.wsht.HornetQHTWorkItemHandler;


      8) In this same module, in register() add the following which also comes from the evaluation sample code:

      try {

          // load up the knowledge base

          KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

          kbuilder.add(ResourceFactory.newClassPathResource("Evaluation.bpmn"), ResourceType.BPMN2);

          KnowledgeBase kbase = kbuilder.newKnowledgeBase();

          StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

          HornetQHTWorkItemHandler humanTaskHandler = new HornetQHTWorkItemHandler(ksession);



          ksession.getWorkItemManager().registerWorkItemHandler("Human Task", humanTaskHandler);

          KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newThreadedFileLogger(ksession, "test", 1000);

          // start a new process instance

          Map<String, Object> params = new HashMap<String, Object>();

          params.put("employee", "krisv");

          params.put("reason", "Yearly performance evaluation");

          ksession.startProcess("com.sample.evaluation", params);

          System.out.println("Process started ...");


          } catch (Throwable t) {




      Upon deploying along with the six jBPM WARs we get this error:


      Caused by: java.lang.IllegalArgumentException: JBAS011470: Persistence unitName was not specified and there are 2 persistence unit definitions in application deployment "myservlet.war".  Either change the application to have only one persistence unit definition or specify the unitName for each reference to a persistence unit.


      I have confirmed that there is exactly one persistence.xml file anywhere in the deployed myservlet folder (it is in jboss-as-7.1.1.Final\standalone\deployments\myservlet.war\WEB-INF\classes\META-INF).


      I have attached the server log.


      Can someone please explain what this error means and how to eliminate it?

        • 1. Re: Getting persistence.xml error while integrating jBPM 5.4 into a J2EE web app



          Do you have the jbpm test jar in your class path? That jar also has a persistence.xml file which defines a persistence unit and might give the error that you have mentioned. Also, since you are using JTA, you can declare the name as follows:

          <persistence-unit name="primary"  transaction-type="JTA">




          • 2. Re: Re: Getting persistence.xml error while integrating jBPM 5.4 into a J2EE web app

            Hi Manny,


            Thank you VERY MUCH!  I removed jbpm-test-5.4.0.Final.jar and the error was eliminated and I now have a successful deployment!


            I have been struggling for several months to find the proper procedure for "integrating" jBPM 5.4 into a J2EE web app for JBoss and with your suggestion I am finally able to do so!  I will mark your reply as the answer (I'd mark it multiple times if I could!) but I am hoping you can answer these follow on questions:


            1) I cannot locate any documentation on the recommended way to integrate jBPM into a J2EE web app for JBoss.  There is a fair amount of documentation (I purchased Salaboy's jBPM 5 Developer Guide) & samples on getting jBPM running with JBoss in a simple Java applet but nothing useful I can find for a J2EE web app.  I have had numerous comments on other questions that "you should use Maven" or "Maven will do this" but these comments are so vague that they do not help.  In my approach I manually added the jBPM run time folder from the jBPM 5.4 Full Installer (which is what set me up for the extra persistence.xml error in the test jar!).  Can you tell me how to locate and add the jBPM 5.4 Maven dependencies so I can "use Maven" as recommended?

            2) I also cannot locate any documentation on the necessary/legitimate contents of persistence.xml for use with jBPM 5.4 (at least with the evaluation sample).  For example, I was told in another question that I must use a JNDI Name of java:jboss/jdbc/jbpm-ds, but with no explanation.  Can you explain why?  Further, you suggested adding 'transaction-type="JTA"'.  Can you point me to materials that explain why I can/should do this and what the required/recommended contents of persistence.xml should be for use with jBPM 5.4?

            3) In general, I have found a great deal of material in the book, forum postings and online documentation for implementation/use of jBPM after it is configured and running.  However, I have had a very difficult time locating the specific details for getting jBPM 5.4 running in a J2EE web app with JBoss.  Can you share how you learned this material so I can be much more self-sufficient?


            Again, thank you very much!


            • 3. Re: Getting persistence.xml error while integrating jBPM 5.4 into a J2EE web app

              Hi Al,


              Happy to hear that my suggestion helped you. I am not using Maven myself so I will not be able to answer the first question.

              For point 2, it was a very difficult process for me to get it right. If you are using persistence and want to integrate transactions, you will need to make use of JTA. If you notice on your persistence.xml, you had provided <jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>. It will not be used till you add 'transaction-type="JTA"' in your persistence unit. Since I am using bitronix as transaction manager, it expects a JTA data source, so I need to tell it from this config to use the available source. Here are the steps that need to be followed (purely from my understanding and long hours spent researching)


              1) To use a transaction manager (I am using bitronix), you first need to have a Data source available in the environment.

              2) You can create a data source programatically (as I am doing in my environment) or use a data source configured on server (possibly using context.xml). I create a PooledDataSource object (pds) using info from a properties file.

              3) Since I am using my own data source, I create a InitialContext object and create a subcontext on it. For example, I need the data source name as "jdbc/jbpm-ds", then I create a subcontext called jdbc.

              Here is how it works:

              InitialContext ctx1 = new InitialContext();


              ctx1.bind("jdbc/jbpm-ds", pds);

              4) This should be done on startup before you invoke EntityManager. This is because when you try to create EntityManagerFactory using your persistence, this data source should be available.

              5) On persistence.xml, I am directly referring to datasource directly without fully qualified name as:    <jta-data-source>jdbc/jbpm-ds</jta-data-source>. If i need to use the datasource from the server context, I will need the fully qualified name. Overall, it doesnt matter what is the name of the data source. The name that you create (jdbc/jbpm-ds or anything else), you need to pass the same name in the persistence.xml as the JTA-data-source. When your process is executing and the registered transaction manager kicks up, it will use this data source for persisting the info.


              So as you see, all this has been based on more than a week of research. All this works for me now, but there is no single source for all this. I have read multiple blogs and posts to get to this understanding. I might be wrong and would be happy if the more experienced on the community could correct my understanding.




              1 of 1 people found this helpful
              • 4. Re: Getting persistence.xml error while integrating jBPM 5.4 into a J2EE web app

                Hi Manny,


                Thanks very much for such a "info rich" response.  I will go see if I can put in play your info on persistence.  One question:


                You say that you are using bitronix.  My understanding is that JBoss 7 has an integrated transaction manager.  If that is correct would you share why you are using bitronix?


                It's both a bit discouraging but perhaps also a bit reassuring to hear that you too have had to struggle to get all of this "up and running".  My initial research discovered quite a few people who felt that jBPM/Drools was of greater flexibility and capability that competitors but they also said it had been very difficult to get it all running.  Seems like that has turned out to be very true!  I realize that this is is all Community supported but it's a shame that such a capable piece of software is so very hard/time consuming  to just get running.


                I'll get back with the results of your procedure but in the meantime I hope you can comment on my bitronix question.


                Again, your help is very much appreciated.



                • 5. Re: Getting persistence.xml error while integrating jBPM 5.4 into a J2EE web app

                  Hi Al,


                  Thanks for the kind words.


                  I understand that Jboss AS has its own transaction manager and you can use that as well. Since my development environment is in tomcat, I am currently using bitronix.

                  Again, from my understanding, to use the server transaction manager, I will need to change my approach from creating a DS programatically to creating it through standalone.xml in the case of JBoss and context.xml in case of tomcat.

                  Second change required will be to register the manager lookup class in persistence.xml to point it to the server transaction manager instead of bitronix.

                  Third, use the datasource with fully qualified name in persistence.xml. Example: java:jboss/datasources/ExampleDS


                  This is purely my understanding and it will be helpful if some experts can confirm if this is the right way to go.


                  I agree that the platform has immense capability and the team is working hard to provide great features. It is however difficult to get it implemented for anyone who just starts. I am fairly new to the platform and have struggled myself to get to the stage where I am. This is the only reason I have started to support the community even more to ensure smoother sailing for new adopters. I fully support the platform and would like to see it progress further.




                  1 of 1 people found this helpful