数据库提交操作是在jbpmcontext.close()方法执行后,事务才提交的. close方法如下:
复制代码
|
其中的autoSave()方法如下:
复制代码
|
一般人都认为是这里将processInstance保存到数据库.其实这里分2种情况,只有当以
jbpmContext.newProcessInstanceForUpdate(processName);方式启动流程时,才会执行这里的操作。
原因是autoSaveProcessInstances通过processDefinition.createProcessInstance()启动时没有值.
autoSave()方法里的循环操作,可以保存流程日志到数据库中.从另一个方面来讲只有以jbpmContext.newProcessInstanceForUpdate(processName);方式启动流程时,流程日志表才有数据.
那么我们的流程是通过processDefinition.createProcessInstance()方式启动的,为什么也能将processInstance保存到数据库呢.原因见
下面的堆栈信息.
EntityInsertAction.<init>(Serializable, Object[], Object, Object, EntityPersister, SessionImplementor) line: 34
DefaultSaveOrUpdateEventListener(AbstractSaveEventListener).performSaveOrReplicate(Object, EntityKey, EntityPersister, boolean, Object, EventSource, boolean) line: 329
DefaultSaveOrUpdateEventListener(AbstractSaveEventListener).performSave(Object, Serializable, EntityPersister, boolean, Object, EventSource, boolean) line: 181
DefaultSaveOrUpdateEventListener(AbstractSaveEventListener).saveWithGeneratedId(Object, String, Object, EventSource, boolean) line: 121
DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(SaveOrUpdateEvent) line: 187
DefaultSaveOrUpdateEventListener.entityIsTransient(SaveOrUpdateEvent) line: 172
DefaultSaveOrUpdateEventListener.performSaveOrUpdate(SaveOrUpdateEvent) line: 94
DefaultSaveOrUpdateEventListener.onSaveOrUpdate(SaveOrUpdateEvent) line: 70
SessionImpl.fireSaveOrUpdate(SaveOrUpdateEvent) line: 507
SessionImpl.saveOrUpdate(String, Object) line: 499
CascadingAction$1.cascade(EventSource, Object, String, Object, boolean) line: 218
Cascade.cascadeToOne(Object, Type, CascadeStyle, Object, boolean) line: 268
Cascade.cascadeAssociation(Object, Type, CascadeStyle, Object, boolean) line: 216
Cascade.cascadeProperty(Object, Type, CascadeStyle, Object, boolean) line: 169
Cascade.cascade(EntityPersister, Object, Object) line: 130
DefaultSaveEventListener(AbstractSaveEventListener).cascadeBeforeSave(EventSource, EntityPersister, Object, Object) line: 431
DefaultSaveEventListener(AbstractSaveEventListener).performSaveOrReplicate(Object, EntityKey, EntityPersister, boolean, Object, EventSource, boolean) line: 265
DefaultSaveEventListener(AbstractSaveEventListener).performSave(Object, Serializable, EntityPersister, boolean, Object, EventSource, boolean) line: 181
DefaultSaveEventListener(AbstractSaveEventListener).saveWithGeneratedId(Object, String, Object, EventSource, boolean) line: 121
DefaultSaveEventListener(DefaultSaveOrUpdateEventListener).saveWithGeneratedOrRequestedId(SaveOrUpdateEvent) line: 187
DefaultSaveEventListener.saveWithGeneratedOrRequestedId(SaveOrUpdateEvent) line: 33
DefaultSaveEventListener(DefaultSaveOrUpdateEventListener).entityIsTransient(SaveOrUpdateEvent) line: 172
DefaultSaveEventListener.performSaveOrUpdate(SaveOrUpdateEvent) line: 27
DefaultSaveEventListener(DefaultSaveOrUpdateEventListener).onSaveOrUpdate(SaveOrUpdateEvent) line: 70
SessionImpl.fireSave(SaveOrUpdateEvent) line: 535
SessionImpl.save(String, Object) line: 523
SessionImpl.save(Object) line: 519
DbPersistenceService.assignId(Object) line: 330
Services.assignId(Object) line: 257
ProcessInstance.<init>(ProcessDefinition, Map, String) line: 137
ProcessInstance.<init>(ProcessDefinition) line: 92
ProcessDefinition.createProcessInstance() line: 125
JpdlServiceImpl.createProcess(String) line: 50
JpdlServiceImpl$$FastClassByCGLIB$$f5b03888.invoke(int, Object, Object[]) line: not available
MethodProxy.invoke(Object, Object[]) line: 149
Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint() line: 700
Cglib2AopProxy$CglibMethodInvocation(ReflectiveMethodInvocation).proceed() line: 149
TransactionInterceptor.invoke(MethodInvocation) line: 106
Cglib2AopProxy$CglibMethodInvocation(ReflectiveMethodInvocation).proceed() line: 171
ExposeInvocationInterceptor.invoke(MethodInvocation) line: 89
Cglib2AopProxy$CglibMethodInvocation(ReflectiveMethodInvocation).proceed() line: 171
Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Object, Method, Object[], MethodProxy) line: 635
JpdlServiceImpl$$EnhancerByCGLIB$$ead8b30c.createProcess(String) line: not available
JpdlProcessTest.testWorkflow() line: 11