task management and persistance questions
tobysaville Jan 4, 2006 11:31 AMHello,
I am having trouble understanding the best time and place to persist my Process Instance when tasks are involved.
I have a servlet that creates a new process instance from a definition which is retrieved via a user managed transaction:
JbpmSession session = JbpmSessionFactory.getInstance().openJbpmSessionAndBeginTransaction() ProcessDefinition def = session.getGraphSession(). findLatestProcessDefinition(?DEF_NAME?); ProcessInstance pi = new ProcessInstance(def); pi.signal(); session.commitTransactionAndClose();
The process instance then arrives at a task node, with an AssignmentHandler associated, which does the following:
public void assign( Assignable assignable, ExecutionContext context ){ assignable.setActorId(?myUsername?); context.getTaskInstance().start(); JbpmSession session = JbpmSessionFactory.getInstance().openJbpmSessionAndBeginTransaction(); session.getGraphSession().saveProcessInstance(context.getProcessInstance()); session.commitTransactionAndClose(); }
However it is failing at the session..getGraphSession().saveProcessInstance(context.getProcessInstance());
Line with the exception:
Illegal attempt to associate a collection with two open sessions
Can you please explain what I am doing wrong here? I have arrived at this junction after trying many different options and I cant think of any other way. I have the following questions:
1.) can I start the transaction instance in the assignment handler? if not, where do I start it?
2.) do I save the process instance in the assignment handler (or from any other class that is part of the process instance execution)? If not, how and where do I carry out the persistence after the process instance is in a wait state? If so, why am i getting the above error when saving?
3.) currently I have 2 JbpmSessionFactorys. 1 for classes not involved in the process instance (servlets etc) and 1 for classes involved in the process instance (actions, assignment handlers etc). How can I have only 1 session factory thats used by all classes? I tried using JNDI, but we are using Tomcat as our application server, and its Initial Context is read only, so I cant place the session factory in there.
Thanks for your help.
toby