[jboss-user] [JBoss jBPM] - Re: Hibernate Error when persist the outer ProcessInstance.
kenees
do-not-reply at jboss.com
Thu Apr 9 08:08:37 EDT 2009
"boercher" wrote : Obviously creation of ProcessInstances involves the database. I've looked up the ProcessInstance constructor:
|
| public ProcessInstance(ProcessDefinition processDefinition, Map<String, Object> variables, String key)
| | {
| | [...]
| | // if this process instance is created in the context of a persistent operation
| | Services.assignId(this);
| | [...]
| | }
| |
| You are surely operating in the context of a persistent operation so this call to this static method of Services (I guess these are the services from the jbpm.cfg.xml) will do some Hibernate stuff.
|
| Since jBPM heavily relies on a database for everything (transaction safety, logging, ...) I would guess that it will be hard to work around that by other means than by crude hacks.
|
| Volker
Yes, Volker, you are right. What I have to do is to extend from the ProcessInstance to create a new type of ProcessInstance -- NonPersistProcessInstance. Code would like:
| public NonPersistProcessInstance(ProcessDefinition processDefinition,
| Map variables, String key) {
|
| if (processDefinition == null)
| throw new JbpmException(
| "can't create a process instance when processDefinition is null");
|
| // initialize the members
| this.processDefinition = processDefinition;
| this.rootToken = new Token(this);
| this.start = Clock.getCurrentTime();
| this.key = key;
|
| // if this process instance is created in the context of a persistent
| // operation
| // DO NOT PERSIST
| //Services.assignId(this);
|
| // create the optional definitions
| Map definitions = processDefinition.getDefinitions();
| // if the state-definition has optional definitions
| if (definitions != null) {
| instances = new HashMap();
| // loop over each optional definition
| Iterator iter = definitions.values().iterator();
| while (iter.hasNext()) {
| ModuleDefinition definition = (ModuleDefinition) iter.next();
| // and create the corresponding optional instance
| ModuleInstance instance = definition.createInstance();
| if (instance != null) {
| addInstance(instance);
| }
| }
| }
|
| // add the creation log
| rootToken.addLog(new ProcessInstanceCreateLog());
|
| // set the variables
| ContextInstance contextInstance = getContextInstance();
| if ((contextInstance != null) && (variables != null)) {
| contextInstance.addVariables(variables);
| }
|
| Node initialNode = rootToken.getNode();
| // fire the process start event
| if (initialNode != null) {
| ExecutionContext executionContext = new ExecutionContext(rootToken);
| processDefinition.fireEvent(Event.EVENTTYPE_PROCESS_START,
| executionContext);
|
| // execute the start node
| initialNode.execute(executionContext);
| }
|
| }
|
I commented the "assignId" method call in the constructor, this seems to be rude, but I don't know if there is any better idea...
Thank you Volker.
View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4224657#4224657
Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4224657
More information about the jboss-user
mailing list