[jboss-user] [jBPM] - Problem persisting tasks

Asad Rauf do-not-reply at jboss.com
Wed Sep 7 14:05:31 EDT 2011


Asad Rauf [http://community.jboss.org/people/imran.h] created the discussion

"Problem persisting tasks"

To view the discussion, visit: http://community.jboss.org/message/625351#625351

--------------------------------------------------------------
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 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.
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/625351#625351]

Start a new discussion in jBPM at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20110907/8fa38c11/attachment-0001.html 


More information about the jboss-user mailing list