2 Replies Latest reply on Mar 3, 2008 7:57 PM by kukeltje

    Injecting the hibernate session

    chrisrjcox

      Hi,

      I have the following code within a Message Driven Bean, I can get it to create a JbpmContext however I'm getting stuck with regards to Injecting the hibernate session...

      Eclipse is stating that I "cannot make a static reference to the none static ethod getCurrentSession() from the type SessionFactory"

      I'm following this from Chaper 7 page 5 on the jbpm guide. (7.1.4)

      package com.distributed.jbpm.mdb;
      
      import javax.ejb.MessageDriven;
      import javax.ejb.ActivationConfigProperty;
      
      import javax.jms.JMSException;
      import javax.jms.Message;
      import javax.jms.MessageListener;
      import javax.jms.TextMessage;
      
      import org.jbpm.JbpmConfiguration;
      import org.jbpm.JbpmContext;
      import org.jbpm.graph.exe.ProcessInstance;
      import org.hibernate.*;
      
      
      
      @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();
      
       public void onMessage(Message inMessage)
       {
       TextMessage textMessage = null;
       try
       {
       if(inMessage instanceof TextMessage)
       {
       textMessage = (TextMessage) inMessage;
       System.out.println("PartTwoMDB: Message received: "+ textMessage.getText());
      
       JbpmContext jbpmContext = jbpmConfiguration.createJbpmContext();
       System.out.println("PartTwoMDB: jbpmContextCreated");
       try
       {
       jbpmContext.setSession(SessionFactory.getCurrentSession());
       String processDefinitionName = "processTwo";
       System.out.println("PartTwoMDB: processDefinitionName * " + processDefinitionName + " * String created.");
       ProcessInstance processInstance = jbpmContext.newProcessInstance(processDefinitionName);
       System.out.println("PartTwoMDB: Instance" + processInstance.toString() + " Loaded.");
       processInstance.signal();
       System.out.println("PartTwoMDB: Instance signal sent.");
       }
       finally
       {
       jbpmContext.close();
       }
      
       }
       else
       {
       System.out.println("PartTwoMDB: Message of wrong type: " + inMessage.getClass().getName());
       }
       }
       catch (JMSException e)
       {
       e.printStackTrace();
       }
       catch (Throwable t)
       {
       t.printStackTrace();
       }
      
       }
      }
      
      


        • 1. Re: Injecting the hibernate session
          kukeltje

          Could you explain jbpm involvement in this? You do not describe where the error occurs, show no stacktrace, I see nothing in here about injecting a hibernate session, though the subject suggests things in that direction.......

          • 2. Re: Injecting the hibernate session
            kukeltje

            Sorry, I was reading your other post in between while posting this.... I do see the injection going on... maybe there is a typo in 7.1.4 and should it be a little different. Look at hibernate how to retrieve the current session