1 2 Previous Next 17 Replies Latest reply on Mar 9, 2010 7:20 PM by pmuir

    Entity Manager Producer Revisited

    jpleed3.john.leediii.minitmarkets.com

      I think I asked this in another thread, but never got a clear answer.


      I have an EntityManager and EntityManagerFactory producer bean, as suggested in section 14.1 of the Weld documentation. It's rather simple:


      @Stateless
      public class IntranetDatabaseProducer {
          @Produces @IntranetDatabase @PersistenceContext(unitName="IntranetPU")
          EntityManager entityManager;
          
          @Produces @IntranetDatabase @PersistenceUnit(unitName="IntranetPU")
          EntityManagerFactory entityManagerFactory;
      }
      



      The only way I can get it to work with anything though is to make it a SLSB. If I make it @SessionScoped or @ApplicationScoped, nothing gets produced and no exceptions are thrown until something tries to use the em reference.


      If I change things around from a field producer to a method producer, I can see it isn't that nothing is being injected but rather that null is being produced. I see output in the log from the producer method, which means that resource injection isn't working here.


      @SessionScoped
      public class IntranetDatabaseProducer implements Serializable {
          @PersistenceContext(unitName="IntranetPU")
          EntityManager entityManager;
      
          @Produces @IntranetDatabase
          public EntityManager produceEntityManager() {
              System.out.println("Producing an entity manager");
              return entityManager;
          }
      }
      



      So what am I missing here? For reference, I'm running Weld 1.0.1-Final on Glassfish v3 full profile.

        1 2 Previous Next