1 Reply Latest reply on Sep 7, 2011 5:26 PM by Asad Rauf

    Problem persisting tasks

    Asad Rauf Newbie

      I am trying to get persistence setup and I am get the following exception:

       

      java.lang.IllegalStateException: A JTA EntityManager cannot use getTransaction()

              at org.hibernate.ejb.AbstractEntityManagerImpl.getTransaction(AbstractEntityManagerImpl.java:324)

              at org.jbpm.task.service.TaskServiceSession.doOperationInTransaction(TaskServiceSession.java:811)

              at org.jbpm.task.service.TaskServiceSession.persistInTransaction(TaskServiceSession.java:786)

              at org.jbpm.task.service.TaskServiceSession.addUser(TaskServiceSession.java:69)

       

      I saw the a relevant thread on this forum: http://community.jboss.org/thread/162939?start=15&tstart=0

       

      According to the advice on this list, I should setup two different persistence units, a separate one for tasks. That works  but I end up persisting just the process info and not the task info. This means I am unable to get tasks for a user who logs in at a later time. I am sure this is not expected behavior. My current code is:

       

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

       

              EntityManagerFactory emfTask = Persistence.createEntityManagerFactory( "org.jbpm.myTask", HibernateConfig.getPersistenceProps() );

             

              Environment env = KnowledgeBaseFactory.newEnvironment();

             

              env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, emf );

              env.set( EnvironmentName.TRANSACTION_MANAGER, TransactionManagerServices.getTransactionManager() );

              env.set( EnvironmentName.TRANSACTION, TransactionManagerServices.getTransactionManager() );

              env.set( EnvironmentName.GLOBALS, new MapGlobalResolver() );

       

              Properties properties = new Properties();

              properties.put("drools.processInstanceManagerFactory", "org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory");

              properties.put("drools.processSignalManagerFactory", "org.jbpm.persistence.processinstance.JPASignalManagerFactory");

              KnowledgeSessionConfiguration config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration(properties);

            

      /* Start Mina server for HT*/

              MinaTaskServer server = new MinaTaskServer(taskService);

              Thread thread = new Thread(server);

              thread.start();

             

              TaskServiceSession taskSession = taskService.createSession();

              CurrentHibernate.setTaskServiceSession(taskSession);

              List<User> users = getSimbaService().getUserService().getAllUsers();

              for(User user: users) {

                taskSession.addUser(new org.jbpm.task.User(user.getUsername()));

              }

              //Build Knowlede Base

              KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();

              kbuilder.add(ResourceFactory.newClassPathResource("META-INF/PermissionRequest.bpmn"), ResourceType.BPMN2);

              KnowledgeBase kbase = kbuilder.newKnowledgeBase();

             

              StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, config, env);

          

      ksession.getWorkItemManager().registerWorkItemHandler("Human Task", new CommandBasedWSHumanTaskHandler(ksession));

              ksession.getWorkItemManager().registerWorkItemHandler("sendPermissionRequest", new PermissionRequestTaskHandler());

             

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

              params.put("description", taskDetails.toString());

              params.put("requesterComments", requesterComments);

              params.put("approver", toUser);

              params.put("permissionRequestItems", taskDetails.toString());

       

           ProcessInstance processInstance = ksession.startProcess("permissionRequest", params);

       

       

      Thanks for your help.