[jboss-user] [JBoss jBPM] - Re: jbpm 3.2 Session Is Closed exception in JobSession

zibi101 do-not-reply at jboss.com
Sat Jan 5 13:53:20 EST 2008


Hi,

I encountered the same problem in spring-managed transactions environment (on jboss 4.2.2)
Here is the solution: 
I register DeleteJobsSynchronization within TransactionSynchronizationManager and extend 
DeleteJobsSynchronization to support Ordered interface. It allows TransactionSynchronizationManager
to execute DeleteJobsSynchronization before SpringSessionSynchronization which closes hibernate session.


  | public class SpringJobSession extends JobSession {   
  | 
  |     Log log = LogFactory.getLog(SpringJobSession.class);
  |     
  |     protected Session session;
  | 
  |     public SpringJobSession(Session pSession) {
  |         super(pSession);
  |         // super.session is private... 
  |         session = pSession;
  |     }
  |     
  |     public void deleteJobsForProcessInstance(ProcessInstance processInstance) {
  |         try {
  |             // we register synchronization within TransactionSynchronizationManager!
  |             TransactionSynchronizationManager.registerSynchronization(
  |                     new DeleteJobsSynchronization(processInstance));
  |         } catch (Exception e) {
  |           log.error(e);
  |           throw new JbpmException("couldn't delete jobs for '"+processInstance+"'", e);
  |         }
  |       }
  |     
  |     // The very important issue here is that TransactionSynchronizationManager, 
  |     // within DeleteJobsSynchronization is registered, uses particular order 
  |     // while performing registered synchronizations. The order is specified by 
  |     // 'Ordered' interface.  We have to set lower value than is specified for 
  |     // SpringSessionSynchronization to force execution of this synchronization 
  |     // before SpringSessionSynchronization will close the hibernate session. 
  |     private class DeleteJobsSynchronization extends TransactionSynchronizationAdapter implements Serializable {
  |         private static final long serialVersionUID = 1L;
  |         ProcessInstance processInstance;
  |         public DeleteJobsSynchronization(ProcessInstance processInstance) {
  |           this.processInstance = processInstance;
  |         }
  |         public void beforeCompletion() {
  |           log.debug("deleting timers for process instance "+processInstance);
  |           Query query = session.getNamedQuery("JobSession.deleteTimersForProcessInstance");
  |           query.setParameter("processInstance", processInstance);
  |           int result = query.executeUpdate();
  |           log.debug(Integer.toString(result)+" remaining timers for '"+processInstance+"' are deleted");
  |           System.out.println(" -> 2 < ------");
  |           log.debug("deleting execute-node-jobs for process instance "+processInstance);
  |           query = session.getNamedQuery("JobSession.deleteExecuteNodeJobsForProcessInstance");
  |           query.setParameter("processInstance", processInstance);
  |           result = query.executeUpdate();
  |           log.debug(Integer.toString(result)+" remaining execute-node-jobs for '"+processInstance+"' are deleted");
  |           System.out.println(" -> 3 < ------");
  |         }
  |         
  |         @Override
  |         public int getOrder() {
  |             // SpringSessionSynchronization.getOrder() returns SessionFactoryUtils.SESSION_SYNCHRONIZATION_ORDER.
  |             return SessionFactoryUtils.SESSION_SYNCHRONIZATION_ORDER - 50;      
  |         }
  |       }
  | }      
  | 


  | public class SpringPersistenceService extends DbPersistenceService {
  | 
  |     public SpringPersistenceService(SpringPersistenceServiceFactory pPersistentServiceFactory) {
  |         super(pPersistentServiceFactory);
  |     }
  | 
  |     public JobSession getJobSession() {
  |         if (jobSession==null) {
  |           Session session = getSession();
  |           if (session!=null) {
  |             jobSession = new SpringJobSession(session);
  |           }
  |         }
  |         return jobSession;
  |     }
  | 
  | }
  | 


  | <jbpm-configuration>
  |   ....
  |   <jbpm-context>
  |     <service name="persistence"
  |         factory="xxxx.workflow.jbpm.service.SpringPersistenceServiceFactory"/>
  |    ....   
  |   </jbpm-context>
  |  

Should I create a jira bug for it or rather inform spring guys about this issue ?

regards
  
  

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4117325#4117325

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4117325



More information about the jboss-user mailing list