动态添加transiton,报错org.hibernate.SessionException: Session is closed!

cghbs22 2012-08-14
大家好,本人正在学习JBPM4,遇到一个问题请大家帮忙分析一下。

根据借鉴http://eminemning.iteye.com/blog/811968的示例,在action层和service层都尝试了(因有人说和spring的事务管理有关),可都行不通,都报Session is closed!,悲剧中,忘有好心人解惑。谢谢!!

spring的事务配置:
<!-- 配置事务管理器 -->
<bean id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
<property name="nestedTransactionAllowed" value="true" />
</bean>


<!-- 配置事务的传播特性 -->
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<!-- 在开发的时候可以这样定义,但部署的时候一定要详细定义 -->
<tx:method name="*" propagation="REQUIRED" />
<!--
<tx:method name="add*" propagation="REQUIRED"/> <tx:method
name="del*" propagation="REQUIRED"/> <tx:method name="update*"
propagation="REQUIRED"/> <tx:method name="*" read-only="true"/>
-->
</tx:attributes>
</tx:advice>

<!-- 配置哪些类哪些方法使用事务-->
<aop:config>
<aop:pointcut id="allManagerMethod"
expression="execution(* com.jbpm.manger.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod" />
</aop:config>

代码如下:
/** 
* 驳回 
* @param task 当前执行的任务 
* @param destActivityName 需要流转到的目的节点 
* @param createTransitionName 动态生成的transition的名称 
*/ 
protected void reject(Task task, String destActivityName,String createTransitionName ) {  
    //这里不会影响事物  
    EnvironmentImpl envImpl = ((EnvironmentFactory)processEngine).openEnvironment();  
    try {  
          
        //动态回退到“窗口收件”   
        ExecutionImpl e = (ExecutionImpl)executionService.findExecutionById(task.getExecutionId());  
 
        ActivityImpl clerkOpinionActivityImpl = e.getActivity();  
          
        ProcessDefinitionImpl processDefinitionImpl = clerkOpinionActivityImpl.getProcessDefinition();  
          
        //生成一个"经办人意见"——>"窗口收件"的transition  
        ActivityImpl applyActivityImpl = processDefinitionImpl.findActivity(destActivityName);  
        TransitionImpl toApply = clerkOpinionActivityImpl.createOutgoingTransition();  
        toApply.setSource(clerkOpinionActivityImpl);  
        toApply.setDestination(applyActivityImpl);  
        toApply.setName(createTransitionName);  
        this.taskService.completeTask(task.getId(),createTransitionName);  
    } catch (Exception e) {  
        e.printStackTrace();  
    }finally{  
        envImpl.close();  
    }  

Global site tag (gtag.js) - Google Analytics