Uploaded image for project: 'DeltaSpike'
  1. DeltaSpike
  2. DELTASPIKE-315

Provide a producer for EntityManagerFactories

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.3-incubating
    • 0.4
    • JPA-Module
    • None

    Description

      I found myself using the following pattern quite often in projects in the last time. I have a @Qualifier UnitName(value) and a producer for a @Dependent EntityManagerFactory for it. The configuration is mostly provided via the persistenceProperties Map in EntityManagerFactory#createEntityManagerFactory(unitname, persistenceProperties);
      We can further tweak the config lookup path and define a route which makes the most sense.

      This can be used to create the EntityManager producer very easily.

      @ApplicationScoped
      public class MyEntityManagerProducer {
      private @Inject @UnitName("orderUnit") EntityManagerFactory emf;

      @Produces @RequestScoped
      public EntityManager createEm()

      { return emf.createEntityManager(); }

      .. + disposer
      }

      Please note that the EMF producer doens't clash with anything else as it only produces EMFs with the Qualifier @UnitName!

      Attachments

        Issue Links

          Activity

            People

              struberg Mark Struberg
              struberg Mark Struberg
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: