6 Replies Latest reply on Jan 27, 2006 9:12 PM by lappi_79

    add new tables to jbpm database

    lappi_79

      Hi,

      web app uses struts, I am trying to use the same database for jbpm and the webapp(is it a good idea/common practice?).
      Also I am trying to use the same session( jbpmsession.getSession() )
      following is the action code
      Contact table is already created in the database.
      This code doesnt create the new record successfully.

      // Let's open a new persistence session
       JbpmSession jbpmSession = jbpmSessionFactory.openJbpmSession();
       // ... and begin a transaction on the persistence session
       jbpmSession.beginTransaction();
      
       Session session = jbpmSession.getSession();
       Transaction Tx = session.beginTransaction();
      
       Contact contact = new Contact();
       contact.setId(1);
       contact.setFirstName("A");
       contact.setLastName("B");
       contact.setEmail("ab@abc.com");
      
       session.save(contact);
       Tx.commit();
      
       GraphSession graphSession = jbpmSession.getGraphSession();
      
       ProcessDefinition processDefinition =
       graphSession.loadProcessDefinition(2);
      
       // create a new process instance to run
       ProcessInstance processInstance = new ProcessInstance(processDefinition);
      
       // Save the process instance along with the task instance
       graphSession.saveProcessInstance(processInstance);
      
       // Commit the transaction
       jbpmSession.commitTransaction();
       // And close the jbpmSession.
       jbpmSession.close();


      following is in hibernate.cfg.xml
      <hibernate-configuration>
      <session-factory>
       <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
       <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/jbpm</property>
       <property name="hibernate.connection.username">root</property>
       <property name="hibernate.connection.password">admin</property>
       <property name="hibernate.connection.pool_size">10</property>
       <!-- other hibernate properties -->
       <property name="hibernate.show_sql">true</property>
      
       <!-- Mapping files -->
       <mapping resource="other.hbm.xml"/>
       </session-factory>
      </hibernate-configuration>
      


      The process definition with id = 2 has been deployed
      I am getting the following error with tomcat when i call the action (code copied earlier):
      2006-01-26 13:09:34 StandardWrapperValve[action]: Servlet.service() for servlet action threw exception
      java.lang.RuntimeException: couldn't load process definition '2'
      at org.jbpm.db.GraphSession.loadProcessDefinition(GraphSession.java:48)
      at trial.AddContact.execute(Unknown Source)
      at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
      at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
      at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
      at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
      at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
      at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
      at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
      at java.lang.Thread.run(Thread.java:595)
      Caused by: org.hibernate.MappingException: Unknown entity: org.jbpm.graph.def.ProcessDefinition
      at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:489)
      at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:64)
      at org.hibernate.impl.SessionImpl.load(SessionImpl.java:549)
      at org.hibernate.impl.SessionImpl.load(SessionImpl.java:544)
      at org.jbpm.db.GraphSession.loadProcessDefinition(GraphSession.java:44)

      Can someone help me identify whats wrong with my code/ configuration? or does it look like any libraries missing or something?

        • 1. Re: add new tables to jbpm database
          lappi_79

          one correction:

          earler error was if contact table was not already created.

          if the contact table is already created then i get the following error msg:

          2006-01-26 13:26:09 StandardWrapperValve[action]: Servlet.service() for servlet action threw exception
          java.lang.ExceptionInInitializerError
          at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
          at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
          at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
          at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
          at java.lang.Class.newInstance0(Class.java:350)
          at java.lang.Class.newInstance(Class.java:303)
          at org.apache.struts.util.RequestUtils.applicationInstance(RequestUtils.java:143)
          at org.apache.struts.action.RequestProcessor.processActionCreate(RequestProcessor.java:280)
          at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:218)
          at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
          at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
          at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
          at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
          at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
          at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
          at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
          at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
          at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
          at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
          at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
          at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
          at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
          at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
          at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
          at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
          at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
          at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
          at java.lang.Thread.run(Thread.java:595)
          Caused by: java.lang.RuntimeException: couldn't execute sql 'create table contact (ID integer not null, FIRSTNAME varchar(255), LASTNAME varchar(255), EMAIL varchar(255), primary key (ID))'
          at org.jbpm.db.JbpmSchema.execute(JbpmSchema.java:235)
          at org.jbpm.db.JbpmSchema.createSchema(JbpmSchema.java:149)
          at trial.AddContact.<clinit>(Unknown Source)
          ... 37 more
          Caused by: java.sql.SQLException: Table 'contact' already exists
          at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2921)
          at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1570)
          at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
          at com.mysql.jdbc.Connection.execSQL(Connection.java:2972)
          at com.mysql.jdbc.Connection.execSQL(Connection.java:2902)
          at com.mysql.jdbc.Statement.executeUpdate(Statement.java:929)
          at org.jbpm.db.JbpmSchema.execute(JbpmSchema.java:230)


          • 2. Re: add new tables to jbpm database
            ralfoeldi

            Hi 'lappi',

            did you see this:

            Caused by: org.hibernate.MappingException: Unknown entity: org.jbpm.graph.def.ProcessDefinition


            This usually means that there is no ProcessDefinition with id = 2. Are you sure you have a ProcessDefinition with the id 2, not version 2. The correct way of accessing ProcessDefinition would be to call GraphSession.findLatestProcessdefinition(). Then you only need to know the name.

            Another point: your doing transactions double. The jbpmSession uses the Hibernate session, so i.e. your trying to start an transaction twice and closing probably the same transaction twice. In a managed env you probably only be flushing Hibernate twice. This might be harmless, but maybe not. It definately isn't a good idea.

            Same or different database / schema / user / 'whatever applies' depends on the env your in and the database your using, e.g. two schemas in Oracle and you need XA transactions. There is no 'standard' solution but it shouldn't be a problem putting everything in one 'database', whatever that is.

            Hope this helps

            Greetings

            • 3. Re: add new tables to jbpm database
              lappi_79

              Hi Rainer,

              Thanks for the reply.
              So I changed my code to create process instance to

              ProcessDefinition processDefinition =
               graphSession.findLatestProcessDefinition("websale");
              ProcessInstance processInstance = new ProcessInstance(processDefinition);
              graphSession.saveProcessInstance(processInstance);

              And I know websale has been deployed.
              But when i execute the above code i get the gollowing exception,
              java.lang.NullPointerException: can't create a process instance when processDefinition is null
              at org.jbpm.graph.exe.ProcessInstance.<init>(ProcessInstance.java:60)
              at trial.AddContact.execute(Unknown Source)
              at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
              at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
              at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
              at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
              at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
              at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
              at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
              at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
              at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
              at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
              at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
              at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
              at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
              at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
              at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
              at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
              at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
              at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
              at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
              at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
              at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
              at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
              at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
              at java.lang.Thread.run(Thread.java:595)

              what could be the problem? i see all transitions from the process in the database.

              • 4. Re: add new tables to jbpm database
                ralfoeldi

                Hi 'lappi',

                sorry for stating the obvious. Your ProcessDefinition is null => there is no ProcessDefinition with the name of "websale", at least not where Hibernate is looking for it.

                Check your database instances, try deploying a ProcessDefinition 'by hand' in the source code (create small xml as String and call ProcessDefinition.parseXXX() ), save that (call GraphSession.deployProcessDefinition()) and see where it appears. Thats where Hibernate is pointed at.

                Greetings

                • 5. Re: add new tables to jbpm database
                  lappi_79

                  Hi Rainer,

                  I cant find GraphSession.deployProcessDefinition() in the jbpm javadoc

                  http://docs.jboss.com/jbpm/v3/javadoc/org/jbpm/db/GraphSession.html

                  I am using jbpm3.0.2

                  Thanks,
                  Lavanya

                  • 6. Re: add new tables to jbpm database
                    lappi_79

                    Hi again,
                    Process definition hello is deployed on the system, hello1 is not!

                    this code :

                    ProcessDefinition processDefinition =
                     graphSession.findLatestProcessDefinition("hello1");
                     ProcessInstance processInstance = new ProcessInstance(processDefinition);
                     graphSession.saveProcessInstance(processInstance);

                    is giving this error:
                    java.lang.RuntimeException: couldn't save process definition 'ProcessDefinition(176484e)'


                    while this code :
                    ProcessDefinition processDefinition =
                     graphSession.findLatestProcessDefinition("hello");
                     ProcessInstance processInstance = new ProcessInstance(processDefinition);
                     graphSession.saveProcessInstance(processInstance);

                    is giving this error:
                    java.lang.NullPointerException: can't create a process instance when processDefinition is null



                    can I get any specific help as to what exactly could be wrong.
                    I can see hello in `jbpm_processdefinition` table.
                    And since the code is behaving diffeently for right and wrong definition names, I am guessing it is looking in the right location.
                    Does this mean that the process has been deployed but not properly.
                    Please help!!