3 Replies Latest reply on Aug 23, 2006 1:32 PM by Eric Ray

    EntityManager not being injected

    Eric Ray Novice

      I have a situation where I need an EM injected into a JSF Converter implementation class and I can't seem to make that happen. All I need to so is take the string value from the getAsObject method and retrieve the appropriate database object.

      At first I thought I needed to make the converter class a SLSB but when I tried that it didn't work either.

      Any thoughts.
      Thanks.
      Eric Ray

        • 1. Re: EntityManager not being injected
          Eric Ray Novice

          Here's the code

          jsf code...

           <h:selectOneMenu value="#{elem.code}" >
           <f:selectItems value="#{element.codeMap}" />
           </h:selectOneMenu>
          


          Converter implementation

           @PersistenceContext(unitName="DC")
           EntityManager em;
          
           public Object getAsObject(FacesContext fContext, UIComponent component, String value)
           throws ConverterException {
           CodeEntity ce = em.find(CodeEntity.class, value);
           return ce;
           }
          


          em is always null. How can that be? This class is inside the container. Even if I make it a Session Bean is still doesn't work.

          Need ideas. Thanks.


          • 2. Re: EntityManager not being injected
            treespace Novice

            The SLSB works and is the logical place to put such code. EM injection will not work just yet -- requires servlet 2.5 compliant container.

            Are you sure your persistence.xml is correct for the "DC" unit and that it references a valid datasource?

            • 3. Re: EntityManager not being injected
              Eric Ray Novice

              Yes, the persistence.xml is correct. I use the EM all throughout my code. I understand the problem is related to the Converter implementation class being instiated by JSF and not the EJB container or something like that. Therefore, injection cannot occur.

              Are you implying this will be fixed in the 2.5 servlet spec?