-
1. Re: jbpmContext.close() save process instance automaticly
salaboy21 May 13, 2008 9:00 AM (in response to joy_wind)Every time that jBPM reach a wait state the process is persisted..
and when you call jbpmContext.close() you are closing a hibernate session so you are flushing all the changes to the database..
Explain why you dont wanna save the changes....??? -
2. Re: jbpmContext.close() save process instance automaticly
joy_wind May 14, 2008 3:44 AM (in response to joy_wind)salaboy21, thx for your response.
I'm a newbie on jbpm. I think we of course sometimes dont want save the process instance.
For example,after create a new process instance, a method will be called to do something. i want to save the process instance only if the call is success returned.If the method call failed(e.g. throws out an exception),i want the new created process instance been discarded.
Since the jbpmContext do has a save method ,so I think it should allow me to control whether save or not. -
3. Re: jbpmContext.close() save process instance automaticly
salaboy21 May 14, 2008 9:43 AM (in response to joy_wind)if you have this scenario
you can try something like this:if(call()) processInstance=ProcessInstance.parseXML...... else processInstance=null
make my point? -
4. Re: jbpmContext.close() save process instance automaticly
kukeltje May 14, 2008 9:53 AM (in response to joy_wind)salaboy is correct. If you want to determine if a process is instance is needed, determine that in advance. If not, just do not start the process.
-
5. Re: jbpmContext.close() save process instance automaticly
joy_wind May 14, 2008 9:16 PM (in response to joy_wind)Determine if create the instance beforehand may be right for the example scenario. Then the question is ,what is the save method good for ? or when the save method of jbpmConext is needed?
-
6. Re: jbpmContext.close() save process instance automaticly
dleerob May 15, 2008 5:26 AM (in response to joy_wind)If you don't want changes to a process or task instance saved or persisted to the db when you close the JbpmContext, you could try calling jbpmContext.setRollbackOnly();
When the JbpmContext is then closed, it should roll back any changes made. That's how I do it anyway, and it works.
As for the save method, I think it is used when creating a new process instance. If I remember correctly, in the jbpm-console source code, when it creates a new process instance, there is a piece of code that goes as follows:// Nothing else saves the process, so we must jbpmContext.save(processInstance);
Not sure why they said 'Nothing else saves the process, so we must'. Perhaps because it's a new process instance?
Hope this helps. -
7. Re: jbpmContext.close() save process instance automaticly
joy_wind May 15, 2008 7:11 AM (in response to joy_wind)Thanks dleerob.
But i still confusing about the issue. because in the userguide doc of jbpm3.2,there are sample code which call save method explicitly. And they say (in section 7.1.2. Convenience methods on JbpmContext) "Note that if you use the xxxForUpdate methods in the JbpmContext, an explicit invocation of the jbpmContext.save is not necessary any more because it will then occur automatically during the close of the jbpmContext" . So it seemed that if you do NOT use the xxxForUpdate methods,you have to call the save method.
I noticed there is a setRollbackOnly() method too. Since it works for you anyway, I will follow. but hope somebody can clarify it. -
8. Re: jbpmContext.close() save process instance automaticly
coolex May 15, 2008 8:15 AM (in response to joy_wind)Hello joy_wind, I would like to know where your code is located. I mean do you start it from a jsp file, servlet?
I tried your code in a jsp file but I always get an error. -
9. Re: jbpmContext.close() save process instance automaticly
kukeltje May 15, 2008 1:02 PM (in response to joy_wind)coolex,
you have a completely different problem, your code looks good... see my other post -
10. Re: jbpmContext.close() save process instance automaticly
joy_wind May 15, 2008 8:56 PM (in response to joy_wind)coolex,
I run my test code as a standalone application(e.g, in a main method), not in a web container.
My test app is like the following:import org.apache.log4j.Logger; import org.jbpm.JbpmConfiguration; import org.jbpm.JbpmContext; import org.jbpm.db.GraphSession; import org.jbpm.graph.def.ProcessDefinition; import org.jbpm.graph.exe.ProcessInstance; public class Test { private static Logger logger = Logger.getLogger(Test.class); public static void main(String[] args) throws Exception { JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance(); JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext(); try { GraphSession graphSession = jbpmContext.getGraphSession(); logger.info("loading definition ..."); ProcessDefinition processDefinition = graphSession .findLatestProcessDefinition("test-process"); logger.info("create new process instance ..."); ProcessInstance processInstance = new ProcessInstance( processDefinition); } finally { logger.info("closing context !"); jbpmContext.close(); } } }
As the code shows,I just create a new processInstance and do nothing else.But after jbpmContext.close(),jbpm create a new instance in my database even if i dont invoke the save method.
By check log output i found jbpm run serveral INSERT sql statements on my database when jbpmContext.close().