WELD-001408 Unsatisfied dependencies when injecting EntityManager

Viewed 18594

I have @Stateless bean which implements two interfaces (remote and local). I have also added @LocalBean anotation for accessing bean with a no-interface view.

@Stateless
@LocalBean
public class WeatherDataBean implements WeatherDataBeanRemote, WeatherDataBeanLocal {
    @Inject
    private EntityManager entityManager;

    public WeatherDataBean () {

    }
    // ....attributes, getter & setter methods ....
}

I use @Inject for this reason taken from this example of JBoss AS7 quickstart:

We use the "resource producer" pattern, from CDI, to "alias" the old fashioned @PersistenceContext injection of the entity manager to a CDI style injection. This allows us to use a consistent injection style (@Inject) throughout the application.

Now previously I have used:

@PersistenceContext(unitName="WeatherStationJPA")
private EntityManager entityManager;

In EJB and it works without any problem. But with @Inject annotation I get this error:

WELD-001408 Unsatisfied dependencies for type [EntityManager] with qualifiers [@Default] at injection point [[field] @Inject private ejb.WeatherDataBean.entityManager]

Here is how I have class Resources defined:

public class Resources {
     @SuppressWarnings("unused")
     @PersistenceContext(unitName="WeatherStationJPA")
     @Produces
     private EntityManager entityManager;

     @Produces
     FacesContext getFacesContext() {
         return FacesContext.getCurrentInstance();
     }
}

Why Is that I get this error if I try to inject entity manager?

EDIT: On request from @LightGuard I am adding packages that I am using to reference annotations:

  1. WeatherDataBean has:

    import javax.ejb.LocalBean;
    import javax.ejb.Stateless;
    import javax.inject.Inject;
    
  2. Resources has:

    import javax.enterprise.inject.Produces;
    import javax.faces.context.FacesContext;
    import javax.inject.Singleton;
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;
    
2 Answers
Related