3 Replies Latest reply on May 18, 2007 10:20 AM by alexg79

    My own EntityManager, how to do it?

    beligum

      Hi all,

      I'd like to use my own class that implements javax.persistence.EntityManager, as a wrapper around the PersistenceContext (to do additional operations on entity beans that contain other EB).
      Is there a way to do this in a clean way, configuration-wise?

        • 1. Re: My own EntityManager, how to do it?
          waynebaylor

          I would suggest using an Entity Access Object (DAO for EJB3) for your entity beans. Within the EAO you could use the EntityManager to make the additional changes you need OR you could call on other EAOs to make the changes for you. This way you don't have to reinvent the entity manager wheel.

          • 2. Re: My own EntityManager, how to do it?
            alexg79

            I was about to ask the same question, but then I saw this post. My solution is to just use

            @EJB ExtEntityManager em;
            instead of
            @PersistenceContext EntityManager em;
            , but if you use multiple persistence units, it may not be such a practical approach.

            • 3. Re: My own EntityManager, how to do it?
              alexg79

              If you need to handle multiple persistence contexts with the same entity manager, you could implement your own PersistenceProvider and overriding Hibernate's methods as necessary to make EntityManagerFactories churn out your own entity manager objects.