Announcement Announcement Module
Collapse
No announcement yet.
How to put the PersistenceContext into Spring manually? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to put the PersistenceContext into Spring manually?

    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:

    Code:
    public abstract class JpaDAO<K, E> {
        @PersistenceContext
        protected EntityManager entityManager;
        ...
    }
    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.
    Last edited by Lars-Blumberg; Feb 24th, 2011, 01:59 AM.
Working...
X