0 Replies Latest reply on Mar 10, 2008 12:18 PM by chrisrjcox

    org.hibernate.SessionException: Session is closed! error on

    chrisrjcox

      Hi,

      I have an issue where I signal my token into the <<end-state>> node at the end of a process, then get a message org.hibernate.SessionException: Session is closed!


      I have a class which signals a token to move the process from one <<task-node>> to the <<end-state>> node.

      The <<end-state>> node has a action handler which is invoked on node-enter, once the token.signal(); is initiated {TAG 1} (from the <<task-node>> prior), this works fine. However once this action handler is complete {TAG 2}. And the token.signal(); is completed {TAG 3}. The token is now in the <<end-state>> {TAG 4} and the jbpmContext.close(); is completed [TAG 5]. Once the Context is closed and my class is finished (there is no more code to implement) {TAG 6} I receive a
      org.hibernate.SessionException: Session is closed! stacktrace.

      Below is a trace from the terminal.

      15:24:03,054 INFO [STDOUT] PartTwoMDB: onMessage: Begining Token token = processInstance.getRootToken();
      15:24:03,054 INFO [STDOUT] PartTwoMDB: onMessage: Completed Token token = processInstance.getRootToken();
      15:24:03,054 INFO [STDOUT] PartTwoMDB: onMessage: Begining token.signal(); {TAG 1}
      15:24:03,061 WARN [ProxyWarnLog] Narrowing proxy to class org.jbpm.graph.node.EndState - this operation breaks ==
      15:24:03,068 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Begining jndi = new InitialContext(); THIS IS THE "SendMessageToQueueBackForPartOne" ACTION HANDLER WITHIN THE <<end-state>> {TAG 2}
      15:24:03,069 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Completed jndi = new InitialContext();
      15:24:03,069 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Begining conFactory = (ConnectionFactory)jndi.lookup('ConnectionFactory');
      15:24:03,069 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Completed conFactory = (ConnectionFactory)jndi.lookup('ConnectionFactory');
      15:24:03,069 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Begining connection = conFactory.createConnection();
      15:24:03,089 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Completed connection = conFactory.createConnection();
      15:24:03,089 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Begining session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      15:24:03,089 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Completed session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      15:24:03,089 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Begining Queue queue = (Queue) jndi.lookup('queue/jbpmQueueOne');
      15:24:03,089 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Completed Queue queue = (Queue) jndi.lookup('queue/jbpmQueueOne');
      15:24:03,090 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Begining producer = session.createProducer(queue);
      15:24:03,090 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Completed producer = session.createProducer(queue);
      15:24:03,090 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Begining ProcessInstance processInstance = context.getProcessInstance();
      15:24:03,090 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Completed ProcessInstance processInstance = context.getProcessInstance();
      15:24:03,090 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Begining Token token = context.getProcessInstance().getRootToken();
      15:24:03,090 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Completed Token token = context.getProcessInstance().getRootToken();
      15:24:03,090 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Begining ContextInstance contextInstance = (ContextInstance) processInstance.getInstance(ContextInstance.class);
      15:24:03,090 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Completed ContextInstance contextInstance = (ContextInstance) processInstance.getInstance(ContextInstance.class);
      15:24:03,091 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Begining processInstanceIDLong = (Long)contextInstance.getLocalVariable('distributedProcessID', token);
      15:24:03,091 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Completed processInstanceIDLong = (Long)contextInstance.getLocalVariable('distributedProcessID', token);
      15:24:03,091 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: processInstanceIDLong is ****209****
      15:24:03,091 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Begining processInstanceID = processInstanceIDLong.longValue();
      15:24:03,092 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Completed processInstanceID = processInstanceIDLong.longValue();
      15:24:03,092 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Begining bandName = (String)contextInstance.getVariable('bandName', token);
      15:24:03,092 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Completed bandName = (String)contextInstance.getVariable('bandName', token);
      15:24:03,092 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: bandName is ****The Shockers****
      15:24:03,092 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Begining DistributedObject distributedObject = new DistributedObject();
      15:24:03,092 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Completed DistributedObject distributedObject = new DistributedObject();
      15:24:03,093 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Begining distributedObject.processID = processInstanceID;
      15:24:03,093 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Completed distributedObject.processID = processInstanceID;
      15:24:03,093 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Begining distributedObject.processID = processInstanceID;
      15:24:03,093 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Completed distributedObject.processID = processInstanceID;
      15:24:03,093 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Begining XStream xstream = new XStream();
      15:24:03,103 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Completed XStream xstream = new XStream();
      15:24:03,104 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Begining xstream.alias('distributedObject', DistributedObject.class);
      15:24:03,104 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Completed xstream.alias('distributedObject', DistributedObject.class);
      15:24:03,104 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Begining String xml = xstream.toXML(distributedObject);
      15:24:03,105 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Completed String xml = xstream.toXML(distributedObject);
      15:24:03,105 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: XStreams has converted the distributedObject to the following xml<distributedObject>
       <processID>209</processID>
       <bandName>The Shockers</bandName>
      </distributedObject>
      15:24:03,105 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Begining textMessage = session.createTextMessage(xml);
      15:24:03,105 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Completed textMessage = session.createTextMessage(xml);
      15:24:03,106 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Begining producer.send(textMessage);
      15:24:03,108 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute: Completed producer.send(textMessage);
      15:24:03,108 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute/finally: jndi != null: Begining jndi.close();
      15:24:03,108 INFO [STDOUT] SendMessageToQueueBackForPartOne: execute/finally: jndi 1= null: Completed jndi.close();
      15:24:03,108 INFO [STDOUT] *******************SendMessageToQueueBackForPartOne - COMPLETED ************************* HERE THE ACTION HANDLER HAS COMPLETED {TAG 2}
      15:24:03,108 INFO [STDOUT] PartTwoMDB: onMessage: Completed token.signal(); {TAG 3}
      15:24:03,108 INFO [STDOUT] PartTwoMDB: onMessage: Current Node EndState(end-state1) {TAG 4}
      15:24:03,108 INFO [STDOUT] PartTwoMDB: onMessage(): Begining jbpmContext.close();
      15:24:03,119 INFO [STDOUT] PartTwoMDB: onMessage(): Completed jbpmContext.close(); {TAG 5}
      15:24:03,121 INFO [STDOUT] *******************PartTwoMDB - COMPLETED ************************* {TAG 6}
      15:24:03,122 WARN [arjLoggerI18N] [com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator_2] TwoPhaseCoordinator.beforeCompletion - failed for com.arjuna.ats.internal.jta.resources.arjunacore.SynchronizationImple@bfad6d
      org.hibernate.SessionException: Session is closed!
       at org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:49)
      


      If i manually move from the <<task-node>> to the <<end-state>> there is no error.

      below is the code moving the token.

      package com.distributed.jbpm.mdb;
      
      import javax.ejb.MessageDriven;
      import javax.ejb.ActivationConfigProperty;
      
      
      import javax.jms.Message;
      import javax.jms.MessageListener;
      import javax.jms.TextMessage;
      
      
      import org.jbpm.JbpmConfiguration;
      import org.jbpm.JbpmContext;
      
      import org.jbpm.context.exe.ContextInstance;
      import org.jbpm.graph.exe.ProcessInstance;
      import org.jbpm.graph.exe.Token;
      
      import com.thoughtworks.xstream.XStream;
      
      
      
      @MessageDriven(activationConfig =
       {
       @ActivationConfigProperty(propertyName="acknowledgeMode", propertyValue = "Auto-acknowledge"),
       @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
       @ActivationConfigProperty(propertyName="destination", propertyValue="/queue/jbpmQueueTwo")
       })
      
      public class PartTwoMDB implements MessageListener
      {
       static JbpmConfiguration jbpmConfiguration = JbpmConfiguration.getInstance();
      
       long distributedProcessInstanceID;
      
      
      
       public void onMessage(Message inMessage)
       {
       System.out.println("PartTwoMDB: onMessage: Started");
       TextMessage textMessage = null;
       try
       {
       if(inMessage instanceof TextMessage)
       {
       textMessage = (TextMessage) inMessage;
       System.out.println("PartTwoMDB: onMessage: Message received: "+ textMessage.getText());
      
       System.out.println("PartTwoMDB: onMessage: Begining XStream xstream = new XStream();");
       XStream xstream = new XStream();
       System.out.println("PartTwoMDB: onMessage: Completed XStream xstream = new XStream();");
      
       System.out.println("PartTwoMDB: onMessage: Begining xstream.alias('distributedObject', DistributedObject.class);");
       xstream.alias("distributedObject", DistributedObject.class);
       System.out.println("PartTwoMDB: onMessage: Completed xstream.alias('distributedObject', DistributedObject.class);");
      
       System.out.println("PartTwoMDB: onMessage: Begining String xml = textMessage.getText();");
       String xml = textMessage.getText();
       System.out.println("PartTwoMDB: onMessage: Completed String xml = textMessage.getText();");
      
       System.out.println("PartTwoMDB: onMessage: Begining DistributedObject distributedObject = (DistributedObject)xstream.fromXML(xml);");
       DistributedObject distributedObject = (DistributedObject)xstream.fromXML(xml);
       System.out.println("PartTwoMDB: onMessage: Completed DistributedObject distributedObject = (DistributedObject)xstream.fromXML(xml);");
       System.out.println("PartTwoMDB: onMessage: distributedObject: "+ distributedObject.processID);
      
      
      
       System.out.println("PartTwoMDB: onMessage: Begining JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();");
       JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
       System.out.println("PartTwoMDB: onMessage: Completed JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();");
       try
       {
      
      
       System.out.println("PartTwoMDB: onMessage: Begining ProcessInstance processInstance = jbpmContext.newProcessInstance('processTwo');");
       ProcessInstance processInstance = jbpmContext.newProcessInstance("processTwo");
       System.out.println("PartTwoMDB: onMessage: Completed ProcessInstance processInstance = jbpmContext.newProcessInstance('processTwo');");
      
       System.out.println("PartTwoMDB: onMessage: Current Node " + processInstance.getRootToken().getNode());
       System.out.println("PartTwoMDB: onMessage: Current running process " + processInstance.getId());
      
       System.out.println("PartTwoMDB: onMessage: Begining ContextInstance contextInstance = (ContextInstance) processInstance.getInstance(ContextInstance.class);");
       ContextInstance contextInstance = (ContextInstance) processInstance.getInstance(ContextInstance.class);
       System.out.println("PartTwoMDB: onMessage: Completed ContextInstance contextInstance = (ContextInstance) processInstance.getInstance(ContextInstance.class);");
      
       distributedProcessInstanceID = distributedObject.processID;
      
       System.out.println("PartTwoMDB: onMessage: Begining contextInstance.setVariable('distributedProcessID', distributedProcessInstanceID);");
       contextInstance.setVariable("distributedProcessID", distributedProcessInstanceID);
       System.out.println("PartTwoMDB: onMessage: Completed contextInstance.setVariable('distributedProcessID', distributedProcessInstanceID);");
      
       System.out.println("PartTwoMDB: onMessage: Begining contextInstance.setVariable('bandName', 'The Shockers');");
       contextInstance.setVariable("bandName", "The Shockers");
       System.out.println("PartTwoMDB: onMessage: Completed contextInstance.setVariable('bandName', 'The Shockers');");
      
       System.out.println("PartTwoMDB: onMessage: Begining Token token = processInstance.getRootToken();");
       Token token = processInstance.getRootToken();
       System.out.println("PartTwoMDB: onMessage: Completed Token token = processInstance.getRootToken();");
      
       System.out.println("PartTwoMDB: onMessage: Begining token.signal();");
       token.signal();
       System.out.println("PartTwoMDB: onMessage: Completed token.signal();");
      
       System.out.println("PartTwoMDB: onMessage: Current Node " + processInstance.getRootToken().getNode());
      
      
      
      
       }
       finally
       {
       System.out.println("PartTwoMDB: onMessage(): Begining jbpmContext.close();");
       jbpmContext.close();
       System.out.println("PartTwoMDB: onMessage(): Completed jbpmContext.close();");
       System.out.println("*******************PartTwoMDB - COMPLETED *************************");
       }
      
       }
       else
       {
       System.out.println("PartTwoMDB: onMessage(): Message of wrong type: " + inMessage.getClass().getName());
       }
       }
       catch (Throwable t)
       {
       System.out.println("PartTwoMDB: Throwable cought");
       t.printStackTrace();
       }
      
       }
      }