How to do manual Persistence Context propagation in Spring?
We are managing the creation of the EntityManagers in our Spring based application by ourselves ("application managed entity managers") since we need to open the transaction handling to the users of our Spring application (see my preceding question Managing database transactions manually in a Spring/Hibernate environment).
A resulting draw back of this approach is, that currently we have to pass the EntityManager instance of the current context to every DAO. But we want to continue having Spring managing the PersistenceContext for us by using the correspondent annotation:
Considering that the EntityManagers are application managed, how can we have Spring continuing injecting the PersistenceContext as if it would manage the EntityManagers by itself? Is there a way to access the PersistenceContext and inject it our EntityManager (manual persistence context propagation)? On a per thread-basis our EntityManagers don't change.Code:public abstract class JpaDAO<K, E> { @PersistenceContext protected EntityManager entityManager; ... }


Reply With Quote
