I tried to research this before on this forum and I don't think that there is a consensus on how to make jBPM to work seamlessly with JPA/Spring
We implemented an approach that works for us and I figured I will describe it here and see if there is any feedback from the community
thanks,
gelos
----------------------------------------------------------------------------------
- problem overview
- when JPA/Spring is used the desire is to make jBPM to join JPA transactions seamlessly
- the issue boils down to Hibernate sessions - how to inject sessions managed by Spring to jBPM
- Spring manages EntityManagerFactory and EntityManager objects and a common approach (which we use) is to use @PersistenceContext() annotation in DAO objects and have Spring inject EntityManager instances (which are wrappers around Hibernate sessions) into DAOs
- so we need to get a hold of EntityManager, get the underlying Hibernate session and provide it to jBPM when it asks for it
- solution overview
- implement custom jBPM wire object for HibernateSession
- in the object descriptor make a call to a bridge object that uses @PersistenceContext() and is managed by Spring and get Hibernate session from it every time jBPM needs it
see the attached files for details. code has comments in it