Sunday, April 5, 2009

JBPM+ JPA sharing same session

Hi All,

I was working on the aspect that if we have to use jBPM in the environment where we already have JPA based session management.

In this scenario, we have no intention to use jBPM connection rather we want to share the connection with JPA.

To achieve this, I cameup with one simple solution i.e. injecting the JPA session to the jBPM session.

In order to inject, please follow the following steps to avoid the jBPM hibernate connection.

Step 1) Create the EntityManger and get the Session

EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("unitName");

EntityManager entityManger = entityManagerFactory.createEntityManger();

org.hibernate.Session jpaSession =(Session) entityManager.getDelegate();

Step 2) Now get the JbpmContext and inject above session into it

JbpmConfiguration configuration = JbpmConfiguration.getInstance();

JbpmContext jbomContext = configuration.createJbpmContext();

jbpmContext.setSession(jpaSession);



In this way we can avoid the multiple JDBC connections of JPA and jBPM.

Cheers and enjoy the jBPM





No comments: