Injecting the hibernate session
chrisrjcox Mar 3, 2008 11:29 AMHi,
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();
}
}
}