3 Replies Latest reply on Jul 21, 2014 1:40 AM by swiderski.maciej

    Using Persistence

    cgwang1992

      Hi Everyone,

       

      I am trying to understand/learn persistence but have been unsuccessful as there aren't good guides on how to get started. I have been following the documentation online as well as examples found throughout the forums but nothing has been fruitful.

      Can anyone point me to a step by step guide for using persistence from a simple task with a log to viewing this log within the database through a GUI?

      I have created a persistence.xml file and this is how I have set-up my environment.

       

          JBPMHelper.startH2Server();

          JBPMHelper.setupDataSource();

          EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.domain");

       

         

          RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newEmptyBuilder().entityManagerFactory(emf)

                                          //.knowledgeBase(kbase)

                                          .addAsset(ResourceFactory.newClassPathResource("newRule.drl"), ResourceType.DRL)

                                          .addAsset(ResourceFactory.newClassPathResource("sample.bpmn"), ResourceType.BPMN2).get();

       

          RuntimeManager manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);

         

          RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());

       

          KieSession ksession = runtime.getKieSession();




      With my persistence.xml


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

       

      <persistence

            version="2.0"

            xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd

            http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"

            xmlns="http://java.sun.com/xml/ns/persistence"

            xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"

            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

       

          <persistence-unit name="org.jbpm.domain" transaction-type="JTA">

          <provider>org.hibernate.ejb.HibernatePersistence</provider>

          <jta-data-source>jdbc/jbpm-ds</jta-data-source>

          <mapping-file>META-INF/JBPMorm.xml</mapping-file>

          <class>org.drools.persistence.info.SessionInfo</class>

          <class>org.jbpm.persistence.processinstance.ProcessInstanceInfo</class>

          <class>org.drools.persistence.info.WorkItemInfo</class>

          <class>org.jbpm.persistence.correlation.CorrelationKeyInfo</class>

          <class>org.jbpm.persistence.correlation.CorrelationPropertyInfo</class>

          <class>org.jbpm.runtime.manager.impl.jpa.ContextMappingInfo</class>

       

          <properties>

          <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>

          <property name="hibernate.max_fetch_depth" value="3"/>

          <property name="hibernate.hbm2ddl.auto" value="update"/>

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

          <property name="hibernate.transaction.jta.platform"

                    value="org.hibernate.service.jta.platform.internal.BitronixJtaPlatform"/>

            </properties>

        </persistence-unit>

      </persistence>

      I was wondering where I can find the H2 database that I will be persisting my information? I haven't told the program to store anything yet but as I understand it there is a GUI that allows me to view the the entries that are currently held within the H2?

      When I try to access localhost:8080, I have my Jboss AS 7 Server console up since I followed the installer on the documentation page and it starts up this server for me. Is the H2 Embedded into the AS 7 console somehow?

      Also, I ran a sample maven project which will also start the H2 server and execute a task. But where can I see the result if I cannot access the H2 server.


      JBPMHelper.startH2Server();

              JBPMHelper.setupDataSource();

              EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.persistence.jpa");

              RuntimeEnvironmentBuilder builder = RuntimeEnvironmentBuilder.Factory.get()

                  .newDefaultBuilder().entityManagerFactory(emf)

                  .knowledgeBase(kbase);

              return RuntimeManagerFactory.Factory.get()

                  .newSingletonRuntimeManager(builder.get(), "com.sample:example:1.0");

          }


      // let john execute Task 1

              List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");

              TaskSummary task = list.get(0);

              System.out.println("John is executing task " + task.getName());

              taskService.start(task.getId(), "john");

              taskService.complete(task.getId(), "john", null);