4 Replies Latest reply on Jul 6, 2005 10:56 AM by donniedarko

    Spec or Tutorial vague on EntityManagerFactory

    donniedarko

      I find the spec or maybe the tutorial (or both) a little vague on the usage/behavior of the EntityManagerFactory.

      The tutorial says:


      EntityManagerFactory is a service that allows you to manually create and managed EntityManager instances. It is not recommended for you to use this feature as you should be letting the application server manage EntityManager instances. EntityManagerFactory's are really for out-of-container applications that use EJB persistence.

      which I interpret as one should not use it for container managed persistence.
      However in the persistence specification under chapter "5.2.1Obtaining a container managed Entity Manager" it says:

      A container-managed entity manager is obtained by the application through dependency injection or
      through JNDI lookup, or by calling EntityManagerFactory.getEntityManager(). The
      container manages the creation of the entity manager and handles the closing of the entity manager
      transparently to the application.

      which I interpret that one should be able to use the EntityManagerFactory to produce container managed entitymanagers "on the fly" and the still the container should handle closing etc of the manager.
      This is related to the unsolved issue described in

      http://www.jboss.org/index.html?module=bb&op=viewtopic&t=65869

      The spec continues to talk about the EntityManagerFactory in following chapters in the context of container managed entitymanagers.

      Can someone enlighten me?
      Can I or can I not use the EntityManagerFactory for container managed entitymanagers to solve my issue described in the link above?

      Best regards
      Jon Åkerström
      http://www.lightminds.com